Help us shape the future of Go! Take the 2026 Go Developer Survey

response

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

README

response

response contains small response helpers without an application-specific error schema.

response.WriteJSON(w, http.StatusCreated, map[string]string{"id": "42"})

writer := response.NewStatusWriter(w)
next.ServeHTTP(writer, r)
if writer.Status >= http.StatusInternalServerError {
    // record application diagnostics
}

WriteJSON and WriteXML set their content types. StatusWriter records the first final HTTP status and preserves support for http.ResponseController. IsLocalPath validates a root-relative redirect target before your application uses it.

Documentation

Overview

Package response provides small, transport-neutral HTTP response helpers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsLocalPath

func IsLocalPath(value string) bool

IsLocalPath reports whether value is safe to use as a root-relative redirect.

func WriteJSON

func WriteJSON(w http.ResponseWriter, status int, value any)

WriteJSON writes value as a JSON response.

func WriteXML

func WriteXML(w http.ResponseWriter, status int, value any) error

WriteXML writes value as indented XML with an XML declaration.

Types

type StatusWriter

type StatusWriter struct {
	http.ResponseWriter
	Status int
}

StatusWriter records the final HTTP status while preserving response-controller support.

func NewStatusWriter

func NewStatusWriter(w http.ResponseWriter) *StatusWriter

NewStatusWriter wraps w with final-status diagnostics.

func (*StatusWriter) FlushError

func (w *StatusWriter) FlushError() error

FlushError flushes the underlying response after recording an implicit status.

func (*StatusWriter) Unwrap

func (w *StatusWriter) Unwrap() http.ResponseWriter

Unwrap returns the underlying response writer.

func (*StatusWriter) Write

func (w *StatusWriter) Write(data []byte) (int, error)

Write records an implicit successful status before writing data.

func (*StatusWriter) WriteHeader

func (w *StatusWriter) WriteHeader(status int)

WriteHeader records the first final status before passing it through.

Jump to

Keyboard shortcuts

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