Last active
April 12, 2020 07:24
-
-
Save presmihaylov/67fce7b32d7b6fed86019774f1dfba7c to your computer and use it in GitHub Desktop.
First try at Go http handler
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 httphandler | |
| import "net/http" | |
| // Handler for http requests | |
| type Handler struct { | |
| mux *http.ServeMux | |
| } | |
| // New http handler | |
| func New(s *http.ServeMux) *Handler { | |
| h := Handler{s} | |
| h.registerRoutes() | |
| return &h | |
| } | |
| // RegisterRoutes for all http endpoints | |
| func (h *Handler) registerRoutes() { | |
| h.mux.HandleFunc("/", h.hello) | |
| } | |
| func (h *Handler) hello(w http.ResponseWriter, r *http.Request) { | |
| w.WriteHeader(200) | |
| w.Write([]byte("Hello World")) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment