Skip to content

Instantly share code, notes, and snippets.

@chew-z
Created January 2, 2020 12:19
Show Gist options
  • Save chew-z/d91d9eb6faf7c26d9da12ab81ca33b11 to your computer and use it in GitHub Desktop.
Save chew-z/d91d9eb6faf7c26d9da12ab81ca33b11 to your computer and use it in GitHub Desktop.
steps:
- name: 'gcr.io/cloud-builders/gcloud'
args: ['functions', 'deploy', 'HelloHTTP', '--trigger-http', '--runtime', 'go111', '--entry-point', 'HelloHTTP', '--region', 'europe-west1']
dir: 'CloudFunctions'
package helloworld
import (
"net/http"
)
var mux = newMux()
//HelloHTTP represents cloud function entry point
func HelloHTTP(w http.ResponseWriter, r *http.Request) {
mux.ServeHTTP(w, r)
}
func newMux() *http.ServeMux {
mux := http.NewServeMux()
mux.HandleFunc("/", zero)
mux.HandleFunc("/one", one)
mux.HandleFunc("/two", two)
mux.HandleFunc("/three", three)
return mux
}
func zero(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("hello from /"))
}
func one(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("hello from one"))
}
func two(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("hello from two"))
}
func three(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("hello from three"))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment