Documentation
¶
Index ¶
Constants ¶
View Source
const (
// MimeTypeNOSNIFF prevents browsers from MIME type sniffing
MimeTypeNOSNIFF = "nosniff"
)
Variables ¶
This section is empty.
Functions ¶
func JSONError ¶
func JSONError(w http.ResponseWriter, err *Error, code int)
JSONError writes a JSON-formatted error response. It sets appropriate headers (Content-Type, X-Content-Type-Options) and writes the error with the given status code.
func WriteError ¶
WriteError intelligently writes an error response based on the request's Accept and Content-Type headers. If the client expects JSON, it responds with JSONError; otherwise, it falls back to plain text via http.Error.
Types ¶
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error represents a structured error response for JSON APIs. It implements both error and fmt.Stringer interfaces.
func (*Error) MarshalJSON ¶
MarshalJSON implements json.Marshaler for consistent JSON error format. Produces: {"error":"message"}
Click to show internal directories.
Click to hide internal directories.