package main import ( "encoding/json" "fmt" "log" "net/http" "time" ) type NewMeetingResponse struct { LastMeeting time.Time `json:"LastMeetingTime"` } var lastMeeting time.Time func httpGetMeeting(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") err := json.NewEncoder(w).Encode(NewMeetingResponse{lastMeeting}) if err != nil { log.Fatal(err) } } func httpCreateMeeting(w http.ResponseWriter, r *http.Request) { lastMeeting = time.Now() w.Header().Set("Content-Type", "application/json") json.NewEncoder(w).Encode(NewMeetingResponse{lastMeeting}) } func meetEndpoint(w http.ResponseWriter, r *http.Request) { switch r.Method { case "GET": httpGetMeeting(w, r) case "POST": httpCreateMeeting(w, r) default: w.WriteHeader(405) fmt.Fprintf(w, "HTTP method must be GET or POST") } }