Return a JSON object if the response is successful
Signed-off-by: Oliver Davies <oliver@oliverdavies.uk>
This commit is contained in:
parent
ffc74d88ed
commit
075bbaac5e
1 changed files with 11 additions and 2 deletions
|
@ -10,9 +10,18 @@ import (
|
|||
func handler(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Println("Running handler...")
|
||||
|
||||
w.WriteHeader(getResponseCode(r))
|
||||
code := getResponseCode(r)
|
||||
|
||||
w.WriteHeader(code)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(map[string]any{})
|
||||
|
||||
if (code != 200) {
|
||||
json.NewEncoder(w).Encode(map[string]any{})
|
||||
} else {
|
||||
json.NewEncoder(w).Encode(map[string]string{
|
||||
"name": "Oliver Davies",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func getResponseCode(r *http.Request) int {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue