helper

package
v0.0.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 23, 2026 License: MIT Imports: 6 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func WriteError(w http.ResponseWriter, r *http.Request, err string, code int)

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 NewError

func NewError(error string) *Error

NewError creates a new Error with the given message.

func (*Error) Error

func (e *Error) Error() string

Error returns the error message, implementing the error interface.

func (*Error) MarshalJSON

func (e *Error) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler for consistent JSON error format. Produces: {"error":"message"}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL