Created
June 5, 2017 20:20
-
-
Save ecerulm/31a8bbd3773a14517e10581a2a33959d 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
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