Documentation
¶
Index ¶
- func EchoError(ctx context.Context, c *echo.Context, code int, message string, err error) error
- func GetOperation(ctx context.Context) string
- func GetResource(ctx context.Context) string
- func NewOperationContext(ctx context.Context, operation, resource string) context.Context
- func SetOperation(ctx context.Context, operation string) context.Context
- func WriteError(ctx context.Context, w http.ResponseWriter, code int, message string, ...)
- func WriteJSON(w http.ResponseWriter, code int, payload any) error
- func WriteJSONWithChecksum(w http.ResponseWriter, code int, payload any) error
- type OperationKey
- type ResponseWriter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetOperation ¶
GetOperation retrieves the operation name from context, or "Unknown" if not set.
func GetResource ¶
GetResource retrieves the resource identifier from context, or "" if not set.
func NewOperationContext ¶
NewOperationContext creates a new context with operation metadata.
func SetOperation ¶
SetOperation returns a new context with the operation name updated. This follows the idiomatic context pattern - immutable values.
func WriteError ¶
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.