Created
January 2, 2020 12:19
-
-
Save chew-z/d91d9eb6faf7c26d9da12ab81ca33b11 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
steps: | |
- name: 'gcr.io/cloud-builders/gcloud' | |
args: ['functions', 'deploy', 'HelloHTTP', '--trigger-http', '--runtime', 'go111', '--entry-point', 'HelloHTTP', '--region', 'europe-west1'] | |
dir: 'CloudFunctions' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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