response

package
v0.0.6-alpha Latest Latest
Warning

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

Go to latest
Published: May 27, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package response provides utilities for writing HTTP responses in the Zero server. It includes functions for writing JSON responses, error responses, and setting response headers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InternalServerError

func InternalServerError(ctx context.Context, w http.ResponseWriter, err error)

InternalServerError writes a generic 500 response to the client and logs the real error server-side

func SetHeader

func SetHeader(w http.ResponseWriter, key, value string)

SetHeader sets a response header with the given key and value

func StatusCode

func StatusCode(w http.ResponseWriter) int

StatusCode returns the status code of the response

func Write

func Write(ctx context.Context, w http.ResponseWriter, contentType string, statusCode int, data []byte)

Write writes a response with the given content type, status code, and data

func WriteError

func WriteError(ctx context.Context, w http.ResponseWriter, statusCode int, err error)

WriteError writes an error response with the given status code and error

func WriteErrorMsg

func WriteErrorMsg(ctx context.Context, w http.ResponseWriter, statusCode int, message string)

WriteErrorMsg writes an error response with the given status code and message

func WriteJSON

func WriteJSON(ctx context.Context, w http.ResponseWriter, statusCode int, data any)

WriteJSON writes a JSON response with the given status code and data

Types

type Writer

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

Writer is a wrapper around http.ResponseWriter that provides a status code and a written flag It ensures that the response header is only written once

func Wrap

func Wrap(w http.ResponseWriter) *Writer

Wrap wraps the given http.ResponseWriter in a Writer If the http.ResponseWriter is already a Writer, it returns it Otherwise, it creates a new Writer

func (*Writer) Unwrap

func (rw *Writer) Unwrap() http.ResponseWriter

Unwrap returns the underlying http.ResponseWriter so http.NewResponseController can reach Flusher, Hijacker, etc.

func (*Writer) Write

func (rw *Writer) Write(b []byte) (int, error)

Write writes the given bytes to the response body It ensures that the response header is only written once

func (*Writer) WriteHeader

func (rw *Writer) WriteHeader(code int)

WriteHeader writes the status code to the response header

Jump to

Keyboard shortcuts

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