Skip to content

Instantly share code, notes, and snippets.

@ecerulm
Created June 5, 2017 20:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ecerulm/31a8bbd3773a14517e10581a2a33959d to your computer and use it in GitHub Desktop.
Save ecerulm/31a8bbd3773a14517e10581a2a33959d to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"net/http"
)
func speakHandler(w http.ResponseWriter, req *http.Request) {
switch req.Method {
case "GET":
fmt.Fprintf(w, "Hello World!")
case "POST":
fmt.Fprintf(w, "Thank You!")
case "DELETE":
fmt.Fprintf(w, "Goodbye, World!")
default:
panic("Unrecognized method")
}
}
func mainMux() *http.ServeMux {
mux := http.NewServeMux()
mux.HandleFunc("/speak", speakHandler)
return mux
}
func main() {
http.ListenAndServe(":3000", mainMux())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment