package httpapi import "github.com/gin-gonic/gin" // errorBody is the consistent error envelope: {"error":{"code":"...","message":"..."}}. type errorBody struct { Error errorDetail `json:"error"` } type errorDetail struct { Code string `json:"code"` Message string `json:"message"` } // writeError aborts the request with the standard error envelope. func writeError(c *gin.Context, status int, code, message string) { c.AbortWithStatusJSON(status, errorBody{Error: errorDetail{Code: code, Message: message}}) }