package errors import ( "encoding/json" "fmt" ) type AppError struct { Status int `json:"code"` Message json.RawMessage `json:"message"` } func NewAppError(status int, msg string) *AppError { msgJson, err := json.Marshal(msg) if err != nil { msgJson = []byte(fmt.Sprintf(`{"message":"%s"}`, err.Error())) } return &AppError{status, msgJson} }