Skip to content

Instantly share code, notes, and snippets.

@Maniacal
Created September 25, 2018 18:02
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 Maniacal/60786ff854eff19bb6c2a37dece55b96 to your computer and use it in GitHub Desktop.
Save Maniacal/60786ff854eff19bb6c2a37dece55b96 to your computer and use it in GitHub Desktop.
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