handler

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EchoError

func EchoError(ctx context.Context, c *echo.Context, code int, message string, err error) error

EchoError is a helper for Echo handlers to write errors with proper logging.

func GetOperation

func GetOperation(ctx context.Context) string

GetOperation retrieves the operation name from context, or "Unknown" if not set.

func GetResource

func GetResource(ctx context.Context) string

GetResource retrieves the resource identifier from context, or "" if not set.

func NewOperationContext

func NewOperationContext(ctx context.Context, operation, resource string) context.Context

NewOperationContext creates a new context with operation metadata.

func SetOperation

func SetOperation(ctx context.Context, operation string) context.Context

SetOperation returns a new context with the operation name updated. This follows the idiomatic context pattern - immutable values.

func WriteError

func WriteError(ctx context.Context, w http.ResponseWriter, code int, message string, err error)

WriteError writes an error response with structured logging. Uses the logger from ctx to record the error with context.

func WriteJSON

func WriteJSON(w http.ResponseWriter, code int, payload any) error

WriteJSON marshals the payload to JSON, sets standard headers, and writes the response. Sets Content-Type to "application/json" and Content-Length.

func WriteJSONWithChecksum

func WriteJSONWithChecksum(w http.ResponseWriter, code int, payload any) error

WriteJSONWithChecksum marshals the payload to JSON, adds DynamoDB-style CRC32 checksum header, and writes the response. The checksum is required by the DynamoDB wire protocol. Sets Content-Type to "application/x-amz-json-1.0" and X-Amz-Crc32.

Types

type OperationKey

type OperationKey struct{}

OperationKey is a type-safe context key for storing operation metadata.

type ResponseWriter

type ResponseWriter struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

ResponseWriter wraps http.ResponseWriter and tracks the HTTP status code. Use this when you need to inspect the status after WriteHeader is called.

func NewResponseWriter

func NewResponseWriter(w http.ResponseWriter) *ResponseWriter

NewResponseWriter creates a ResponseWriter that wraps the given http.ResponseWriter.

func (*ResponseWriter) StatusCode

func (w *ResponseWriter) StatusCode() int

StatusCode returns the HTTP status code that was written.

func (*ResponseWriter) Write

func (w *ResponseWriter) Write(b []byte) (int, error)

Write delegates to the wrapped ResponseWriter. If WriteHeader has not been called, the status code defaults to http.StatusOK consistent with the behaviour of the standard library's ResponseWriter.

func (*ResponseWriter) WriteHeader

func (w *ResponseWriter) WriteHeader(code int)

WriteHeader writes the status code and delegates to the wrapped ResponseWriter.

Jump to

Keyboard shortcuts

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