Last active
June 3, 2019 22:40
-
-
Save Duncanian/9d314b9230bbaa7c31369873f5d66188 to your computer and use it in GitHub Desktop.
Handling the endpoint for creating a new event in go-rest-api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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