xhttp

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteErrJSON

func WriteErrJSON(rw http.ResponseWriter, err error, options ...ResponseOption)

WriteErrJSON writes the JSON error into given response writer.

func WriteJSON

func WriteJSON(rw http.ResponseWriter, in interface{}, options ...ResponseOption)

WriteJSON writes the JSON output in given response writer.

Types

type QualityValue

type QualityValue struct {
	Value   string
	Quality float64
}

QualityValue is the structure that contains quality - value pair.

func ParseAcceptEncodingHeader

func ParseAcceptEncodingHeader(header http.Header) []QualityValue

ParseAcceptEncodingHeader parses 'Accept-Encoding' header values sorted by it's quality.

func ParseAcceptHeader

func ParseAcceptHeader(header http.Header) []QualityValue

ParseAcceptHeader parses 'Accept' header values sorted by it's quality.

type ResponseOption

type ResponseOption func(e *ResponseOptions)

ResponseOption is an option for the error function.

func ResponseWithContentType

func ResponseWithContentType(contentType string) ResponseOption

ResponseWithContentType is an option to the http response that sets provided content type.

func ResponseWithDebug added in v0.0.28

func ResponseWithDebug(debug bool) ResponseOption

ResponseWithDebug is an option to the http response that sets provided content type.

func ResponseWithHeader

func ResponseWithHeader(key, value string) ResponseOption

ResponseWithHeader is an option to the http response that sets given header with corresponding value

func ResponseWithStatus

func ResponseWithStatus(status int) ResponseOption

ResponseWithStatus returns an error option that sets given response status.

type ResponseOptions

type ResponseOptions struct {
	Status  int
	Headers map[string]string
	Debug   bool
}

ResponseOptions are the options used to customize HTTP response.

type ResponseWriter

type ResponseWriter struct {
	Status  int
	Buffer  *bytes.Buffer
	Wrapped http.ResponseWriter
}

ResponseWriter is a wrapper implementation for the http.ResponseWriter. It allows to have buffered writer and status. It needs to be used in a middleware so that it could manipulate the output with some compressor or react differently on panic. Look at middleware.ResponseWriter how it is used.

func WrapResponseWriter

func WrapResponseWriter(rw http.ResponseWriter) *ResponseWriter

WrapResponseWriter wraps given response writer and creates an implementation that holds temporary buffer and status.

func (*ResponseWriter) Header

func (r *ResponseWriter) Header() http.Header

Header implements http.ResponseWriter.

func (*ResponseWriter) Write

func (r *ResponseWriter) Write(bytes []byte) (int, error)

Write implements io.Writer.

func (*ResponseWriter) WriteHeader

func (r *ResponseWriter) WriteHeader(statusCode int)

WriteHeader implements http.ResponseWriter.

type Server added in v0.0.15

type Server struct {
	Server *http.Server
}

Server is a wrapper over http.Server that implements xservice.RunnerCloser interface.

func NewHTTPServer added in v0.0.15

func NewHTTPServer(mux http.Handler, addr string) *Server

NewHTTPServer creates a new http server port for the images.

func (*Server) Close added in v0.0.15

func (h *Server) Close(_ context.Context) error

Close stops the http server.

func (*Server) Run added in v0.0.15

func (h *Server) Run() error

Run starts running the server in it's own go routine.

Jump to

Keyboard shortcuts

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