package main import ( "fmt" "net/http" "github.com/jboursiquot/go-proverbs" "encoding/json" ) type Proverb struct { Saying string `json:"saying"` Link string `json:"link"` } func HandleProverbJson(w http.ResponseWriter, r *http.Request) { randomProverb := proverbs.Random() p := Proverb { Saying: randomProverb.Saying, Link: randomProverb.Link, } err := json.NewEncoder(w).Encode(p) if err != nil { http.Error(w, "uups, da ist etwas schief gegangen!", http.StatusInternalServerError) } } func main() { http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("Hallo Proserve!")) }) // Plain Text Endpunkt http.HandleFunc("/text", func(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, proverbs.Random().Saying) }) // JSON Endpunkt http.HandleFunc("/api", HandleProverbJson) http.ListenAndServe(":8000", nil) }