Skip to content

Instantly share code, notes, and snippets.

@presmihaylov
Last active April 12, 2020 07:24
Show Gist options
  • Save presmihaylov/67fce7b32d7b6fed86019774f1dfba7c to your computer and use it in GitHub Desktop.
Save presmihaylov/67fce7b32d7b6fed86019774f1dfba7c to your computer and use it in GitHub Desktop.
First try at Go http handler
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