gobuch/microservices/http-metod-matching/main.go

17 lines
311 B
Go
Raw Normal View History

2020-08-21 04:26:40 +00:00
package main
import "net/http"
func myHandler(res http.ResponseWriter, req *http.Request) {
if req.Method == http.MethodGet {
res.Write([]byte("Hello World"))
} else {
res.WriteHeader(http.StatusMethodNotAllowed)
}
}
func main() {
http.HandleFunc("/", myHandler)
http.ListenAndServe(":8080", nil)
}