You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
627 B
Go

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))
}