func getAndSetHandler(responseWriter http.ResponseWriter, request *http.Request) { request.ParseForm() token := request.Form.Get("token") if validToken(token) { var err error if request.Method == "POST" { recordNote(request.Form) responseWriter.Write([]byte("Got it!")) } else { err = respondWithJSON(responseWriter, SummaryResponse{notable.Notes()}) } if err != nil { http.Error(responseWriter, err.Error(), http.StatusInternalServerError) } } else { fmt.Printf("Invalid token received: %s\n", token) http.Error(responseWriter, "Invalid token", http.StatusForbidden) } }
func main() { if len(notable.Notes()) > 0 { notable.SendEmail() notable.Reset() } }