assist

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2024 License: BSD-2-Clause Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteJSONResponse

func WriteJSONResponse(w http.ResponseWriter, data interface{}, code int, logger log.Logger)

WriteJSONResponse marshals the provided data to a JSON string and writes the data to the http.ResponseWriter

func WriteResponse

func WriteResponse(w http.ResponseWriter, data []byte, code int, logger log.Logger)

WriteResponse writes a response to http.ResponseWriter, handling and logging any errors that may occur.

Types

type ResponseWrapper added in v0.4.0

type ResponseWrapper interface {
	// Header returns the stored http.Header
	Header() http.Header
	// ResponseWriter returns this interface as a http.ResponseWriter
	// This is a convenience function only
	ResponseWriter() http.ResponseWriter
	// Status returns the written status code
	Status() int
	// Write simulates writing data to the writer and returns the predetermined error and write count
	Write([]byte) (int, error)
	// WriteHeader stores the statusCode to be returned for later checking with `ResponseWriter.Status`
	WriteHeader(statusCode int)
}

ResponseWrapper is an interface that wraps an `http.ResponseWriter`, allowing for information to be retrieved for logging or to be used in testing

func NewResponseWrapper added in v0.4.0

func NewResponseWrapper(w http.ResponseWriter) ResponseWrapper

NewResponseWrapper returns a new ResponseWrapper that internally stores the provided http.ResponseWriter

Jump to

Keyboard shortcuts

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