Skip to content

Instantly share code, notes, and snippets.

@marciol
Created July 31, 2015 14:11
Show Gist options
  • Save marciol/48d541edfa9ce9bbef4e to your computer and use it in GitHub Desktop.
Save marciol/48d541edfa9ce9bbef4e to your computer and use it in GitHub Desktop.
// Example of how to use stdlib in go, leveraging the simplicity of solutions without dependencies
// based on https://www.youtube.com/watch?v=yi5A3cK1LNA&feature=youtu.be&t=11m45s
func productHandler(w http.ResponseWriter, r *http.Request) {
key := r.URL.PATH[len("/products/"):]
switch r.Method {
case "GET":
// do get stuff
case "POST":
// do post stuff
default:
http.Error(w, "Method not allowed", 405)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment