Skip to content

Instantly share code, notes, and snippets.

@aquiseb
Created February 4, 2020 10:20
Show Gist options
  • Select an option

  • Save aquiseb/f5e061f8dc2e86e7e3355d48d515f03e to your computer and use it in GitHub Desktop.

Select an option

Save aquiseb/f5e061f8dc2e86e7e3355d48d515f03e to your computer and use it in GitHub Desktop.
Multiple routes in a google cloud function
package function
import (
"net/http"
)
var mux = newMux()
//F represents cloud function entry point
func F(w http.ResponseWriter, r *http.Request) {
mux.ServeHTTP(w, r)
}
func newMux() *http.ServeMux {
mux := http.NewServeMux()
mux.HandleFunc("/one", one)
mux.HandleFunc("/two", two)
mux.HandleFunc("/subroute/three", three)
return mux
}
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