httputils

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2020 License: Apache-2.0 Imports: 4 Imported by: 11

Documentation

Index

Constants

View Source
const (
	ContentType               = "Content-Type"
	AccessControlAllowOrigin  = "Access-Control-Allow-Origin"
	AccessControlAllowHeaders = "Access-Control-Allow-Headers"
	AccessControlAllowMethods = "Access-Control-Allow-Methods"
)

collection of http headers

View Source
const (
	ApplicationJson     = "application/json"
	TextPlain           = "text/plain"
	ApplicationActuator = "application/vnd.spring-boot.actuator.v3+json"
)

collection of common content-type values

Variables

View Source
var (
	// IsHttpInformation returns true if a status code is of the 1xx range (100 - 199).
	IsHttpInformation = statusGroupEqual(statusCodeGroupInfo)

	// IsHttpSuccess returns true if a status code is of the 2xx range (200 - 299).
	IsHttpSuccess = statusGroupEqual(statusCodeGroupSuccess)

	// IsHttpRedirect returns true if a status code is of the 3xx range (300 - 399).
	IsHttpRedirect = statusGroupEqual(statusCodeGroupRedirect)

	// IsHttpClientError returns true if a status code is of the 4xx range (400 - 499).
	IsHttpClientError = statusGroupEqual(statusCodeGroupClientErr)

	// IsHttpServerError returns true if a status code is of the 5xx range (500 - 599).
	IsHttpServerError = statusGroupEqual(statusCodeGroupServerErr)
)

Functions

func IsHttpError

func IsHttpError(code int) bool

IsHttpError returns true if a status code is 4xx or 5xx.

func ReturnJSON

func ReturnJSON(w http.ResponseWriter, code int, v interface{})

ReturnJSON converts a given interface into JSON and writes it into an http response You should not write any additional data to the http.ResponseWriter after this

func WithBody

func WithBody(r *http.Request, v interface{}) (err error)

WithBody reads an HTTP JSON request body and marshals it into a given struct Param v must be a pointer

Types

This section is empty.

Jump to

Keyboard shortcuts

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