Created
September 25, 2018 18:02
-
-
Save Maniacal/60786ff854eff19bb6c2a37dece55b96 to your computer and use it in GitHub Desktop.
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
package main | |
import ( | |
"encoding/json" | |
"net/http" | |
) | |
// Error struct is used to structure the data provided back to the client in the event of an error. | |
type Error struct { | |
Status int `json:"status"` | |
Error string `json:"error"` | |
Description string `json:"description"` | |
} | |
type errorOutput struct { | |
Error `json:"error"` | |
} | |
func errorReturn(w http.ResponseWriter, status int, errorName string, desc string) { | |
w.Header().Set("Content_Type", "application/json") | |
w.WriteHeader(status) | |
e := &errorOutput{ | |
Error: Error{ | |
Status: status, | |
Error: errorName, | |
Description: desc, | |
}, | |
} | |
json.NewEncoder(w).Encode(e) | |
return | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment