Skip to content

Instantly share code, notes, and snippets.

@kaneshin
Created November 28, 2016 16:28
Show Gist options
  • Save kaneshin/4683eb3baa9d4d15a3a9aa4725168b28 to your computer and use it in GitHub Desktop.
Save kaneshin/4683eb3baa9d4d15a3a9aa4725168b28 to your computer and use it in GitHub Desktop.
package main
import (
"log"
"net/http"
)
func pingHandler() func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain")
w.WriteHeader(http.StatusOK)
w.Write([]byte("pong"))
}
}
func echoHandler() func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain")
w.WriteHeader(http.StatusOK)
w.Write([]byte(r.URL.Query().Get("msg")))
}
}
func init() {
http.HandleFunc("/ping", pingHandler())
http.HandleFunc("/echo", echoHandler())
}
func main() {
log.Fatal(http.ListenAndServe(":8080", nil))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment