ps_controller

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteText

func WriteText(ctx context.Context, w http.ResponseWriter, httpStatus int, message string)

WriteText writes an error message as a JSON ErrorResponse. It is exported so that packages that import controller (e.g. internal/access) can write auth errors centrally without a Controller instance.

Types

type Controller

type Controller struct{}

func NewController

func NewController() Controller

func (Controller) WriteError

func (c Controller) WriteError(ctx context.Context, w http.ResponseWriter, err error)

func (Controller) WriteJSON

func (c Controller) WriteJSON(ctx context.Context, w http.ResponseWriter, httpStatus int, data any)

func (Controller) WriteText

func (c Controller) WriteText(ctx context.Context, w http.ResponseWriter, httpStatus int, message string)

type ErrorResponse

type ErrorResponse struct {
	// Message is a human-readable description of what went wrong. Intended for
	// logging and debugging, not for programmatic branching (use errorCode for that).
	Message string `json:"message"`
	// ErrorCode is a stable numeric application error code identifying the error type.
	// Use it for programmatic handling; it does not change across locales or message wording.
	ErrorCode int `json:"errorCode"`
	// Args are optional values interpolated into the message template (e.g. field names
	// or limits). Their order matches the placeholders in the message.
	Args []jsontext.Value `json:"args,omitempty"`
}

ErrorResponse is the body returned for every non-2xx response.

Jump to

Keyboard shortcuts

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