package main import ( "database/sql" "fmt" "net/http" "time" ) type Handler struct { db *sql.DB } func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { fmt.Printf("%s - [%s] (%s) %s\n", time.Now().Format(time.RFC3339), r.RemoteAddr, r.Method, r.URL) switch true { case r.Method == "GET" && r.URL.Path == "/": rsvps, err := GetRsvps(h.db) if err != nil { w.WriteHeader(http.StatusInternalServerError) fmt.Fprintf(w, "%s", err.Error()) return } w.WriteHeader(http.StatusOK) fmt.Fprintf(w, "%#v", rsvps) case r.Method == "POST" && r.URL.Path == "/": r := Rsvp{ id: -1, attending: true, partySize: 2, partyMembers: []Member{ {name: "test", dietaryPreferences: "no meat", child: false}, {name: "; DROP TABLE rsvps", dietaryPreferences: "", child: true}, }, } r.CreateRsvp(h.db) w.WriteHeader(http.StatusAccepted) default: w.WriteHeader(http.StatusNotFound) } }