webutil

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2020 License: GPL-3.0 Imports: 20 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

webutil GoDoc Report card Sourcegraph

Web related utilities.

Contributing

Please read the Code of Conduct & Contributing documents.

License

GNUv3

Documentation

Index

Constants

View Source
const ErrTagHTTPStatusCodeKey = "StatusCode"
View Source
const ErrTypeHTTPPublic = "Public"
View Source
const RequestIDHeaderName = "X-Request-ID"
View Source
const RequestIDKey ctxKeyRequestID = 0

RequestIDKey is the key that holds the unique request ID in a request context.

Variables

View Source
var (
	OfferedContentTypes = []string{
		"application/x-yaml",
		"application/yaml",
		"text/yaml",
		"application/json",
		"text/json",
		"application/xml",
		"text/xml",
		"text/html",
		"text/plain",
	}
)

Functions

func Bind

func Bind(r *http.Request, target interface{}) error

func GetRequestID

func GetRequestID(ctx context.Context) string

func Metrics

func Metrics(registry *prometheus.Registry) func(http.Handler) http.Handler

func NegotiateContentType

func NegotiateContentType(acceptHeader string, offeredContentTypes []string, defaultOffer string) string

NegotiateContentType returns the best offered content type for the request's Accept header. If two offers match with equal weight, then the more specific offer is preferred. For example, text/* trumps */*. If two offers match with equal weight and specificity, then the offer earlier in the list is preferred. If no offers match, then defaultOffer is returned.

func Render

func Render(w http.ResponseWriter, r *http.Request, v interface{})

func RenderWithStatusCode

func RenderWithStatusCode(w http.ResponseWriter, r *http.Request, statusCode int, v interface{})

func RequestID

func RequestID(next http.Handler) http.Handler

func RequestLogger

func RequestLogger(next http.Handler) http.Handler

Types

This section is empty.

Jump to

Keyboard shortcuts

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