package main import ( "encoding/json" "log" "net/http" ) func main() { r := http.NewServeMux() r.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { if r.Method != http.MethodGet { http.Error(w, "Method not allowed", http.StatusMethodNotAllowed) return } w.Header().Set("Content-Type", "application/json") if err := json.NewEncoder(w).Encode(map[string]any{ "question": "Whats the answer to life the universe and everything?", "answer": 42, }); err != nil { log.Fatal(err) return } }) log.Printf(`Starting server on :4000...`) log.Fatal(http.ListenAndServe(":4000", r)) }