Created
May 31, 2019 11:33
-
-
Save Duncanian/f7553b66d643e1250fbe89b7891d3bc8 to your computer and use it in GitHub Desktop.
Handling the endpoint for getting a single 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 getOneEvent(w http.ResponseWriter, r *http.Request) { | |
eventID := mux.Vars(r)["id"] | |
for _, singleEvent := range events { | |
if singleEvent.ID == eventID { | |
json.NewEncoder(w).Encode(singleEvent) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment