Skip to content

Instantly share code, notes, and snippets.

@kaneshin
Created November 28, 2016 16:17
Show Gist options
  • Save kaneshin/71dd2a0a086449dccd13279ccdfe9de1 to your computer and use it in GitHub Desktop.
Save kaneshin/71dd2a0a086449dccd13279ccdfe9de1 to your computer and use it in GitHub Desktop.
package main
import (
"log"
"net/http"
)
func EchoHandler(msg string) 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(msg))
}
}
func init() {
http.HandleFunc("/hello", EchoHandler("hello"))
}
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