http.go 374 B

12345678910111213141516171819
  1. package main
  2. import (
  3. "encoding/json"
  4. "net/http"
  5. )
  6. type statusHandler struct {
  7. status *Status
  8. }
  9. func (sh statusHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
  10. w.Header().Set("Content-Type", "application/json")
  11. en := json.NewEncoder(w)
  12. err := en.Encode(sh.status.get())
  13. if err != nil {
  14. http.Error(w, err.Error(), http.StatusInternalServerError)
  15. }
  16. }