Skip to content

Instantly share code, notes, and snippets.

@Duncanian
Last active June 3, 2019 22:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Duncanian/9d314b9230bbaa7c31369873f5d66188 to your computer and use it in GitHub Desktop.
Save Duncanian/9d314b9230bbaa7c31369873f5d66188 to your computer and use it in GitHub Desktop.
Handling the endpoint for creating a new event in go-rest-api
func createEvent(w http.ResponseWriter, r *http.Request) {
var newEvent event
reqBody, err := ioutil.ReadAll(r.Body)
if err != nil {
fmt.Fprintf(w, "Kindly enter data with the event title and description only in order to update")
}
json.Unmarshal(reqBody, &newEvent)
events = append(events, newEvent)
w.WriteHeader(http.StatusCreated)
json.NewEncoder(w).Encode(newEvent)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment