jsonDumper.go 426 B

12345678910111213141516171819
  1. package server
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "net/http"
  6. )
  7. func (server *Server) jsonDumper(w http.ResponseWriter, r *http.Request) {
  8. json, err := json.Marshal(server)
  9. if err != nil {
  10. fmt.Println("JSON Marshaling error:", err)
  11. w.WriteHeader(http.StatusInternalServerError)
  12. w.Write([]byte("This is my Website"))
  13. }
  14. w.Header().Set("Content-Type", "application/json")
  15. w.WriteHeader(http.StatusOK)
  16. w.Write(json)
  17. }