httputil

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2020 License: MIT Imports: 9 Imported by: 2

Documentation

Index

Constants

View Source
const (
	MIMEApplicationJSON                  = "application/json"
	MIMEApplicationJSONCharsetUTF8       = MIMEApplicationJSON + "; " + charsetUTF8
	MIMEApplicationJavaScript            = "application/javascript"
	MIMEApplicationJavaScriptCharsetUTF8 = MIMEApplicationJavaScript + "; " + charsetUTF8
	MIMEApplicationXML                   = "application/xml"
	MIMEApplicationXMLCharsetUTF8        = MIMEApplicationXML + "; " + charsetUTF8
	MIMEApplicationForm                  = "application/x-www-form-urlencoded"
	MIMEApplicationProtobuf              = "application/protobuf"
	MIMEApplicationMsgpack               = "application/msgpack"
	MIMETextHTML                         = "text/html"
	MIMETextHTMLCharsetUTF8              = MIMETextHTML + "; " + charsetUTF8
	MIMETextPlain                        = "text/plain"
	MIMETextPlainCharsetUTF8             = MIMETextPlain + "; " + charsetUTF8
	MIMEMultipartForm                    = "multipart/form-data"
	MIMEOctetStream                      = "application/octet-stream"
)
View Source
const (
	HeaderAccept                        = "Accept"
	HeaderAcceptEncoding                = "Accept-Encoding"
	HeaderAllow                         = "Allow"
	HeaderAuthorization                 = "Authorization"
	HeaderContentDisposition            = "Content-Disposition"
	HeaderContentEncoding               = "Content-Encoding"
	HeaderContentLength                 = "Content-Length"
	HeaderContentType                   = "Content-Type"
	HeaderCookie                        = "Cookie"
	HeaderSetCookie                     = "Set-Cookie"
	HeaderIfModifiedSince               = "If-Modified-Since"
	HeaderLastModified                  = "Last-Modified"
	HeaderLocation                      = "Location"
	HeaderUpgrade                       = "Upgrade"
	HeaderVary                          = "Vary"
	HeaderWWWAuthenticate               = "WWW-Authenticate"
	HeaderXForwardedProto               = "X-Forwarded-Proto"
	HeaderXHTTPMethodOverride           = "X-HTTP-Method-Override"
	HeaderXForwardedFor                 = "X-Forwarded-For"
	HeaderXRealIP                       = "X-Real-IP"
	HeaderServer                        = "Server"
	HeaderOrigin                        = "Origin"
	HeaderAccessControlRequestMethod    = "Access-Control-Request-Method"
	HeaderAccessControlRequestHeaders   = "Access-Control-Request-Headers"
	HeaderAccessControlAllowOrigin      = "Access-Control-Allow-Origin"
	HeaderAccessControlAllowMethods     = "Access-Control-Allow-Methods"
	HeaderAccessControlAllowHeaders     = "Access-Control-Allow-Headers"
	HeaderAccessControlAllowCredentials = "Access-Control-Allow-Credentials"
	HeaderAccessControlExposeHeaders    = "Access-Control-Expose-Headers"
	HeaderAccessControlMaxAge           = "Access-Control-Max-Age"

	HeaderStrictTransportSecurity = "Strict-Transport-Security"
	HeaderXContentTypeOptions     = "X-Content-Type-Options"
	HeaderXXSSProtection          = "X-XSS-Protection"
	HeaderXFrameOptions           = "X-Frame-Options"
	HeaderContentSecurityPolicy   = "Content-Security-Policy"
	HeaderXCSRFToken              = "X-CSRF-Token"
)

Variables

View Source
var (
	ErrMissingRequiredArgument = errors.New("missing required argument")
)
View Source
var (
	ErrUnableToMarshalForm = errors.New("unable to marshal form")
)

Functions

func BlobResponse

func BlobResponse(w http.ResponseWriter, status int, contentType string, b []byte) error

func FormResponse

func FormResponse(w http.ResponseWriter, status int, value interface{}) error

func IP

func IP(req *http.Request) string

func JSONResponse

func JSONResponse(w http.ResponseWriter, status int, value interface{}, debug ...bool) error

func MarshalForm

func MarshalForm(v interface{}) ([]byte, error)

func NewHandler

func NewHandler(method string, h http.Handler) http.Handler

func NewHandlerFunc

func NewHandlerFunc(method string, h http.HandlerFunc) http.Handler

func ParseBool

func ParseBool(r *http.Request, key string, required ...bool) (bool, error)

func ParseFloat32

func ParseFloat32(r *http.Request, key string, required ...bool) (float32, error)

func ParseFloat64

func ParseFloat64(r *http.Request, key string, required ...bool) (float64, error)

func ParseInt

func ParseInt(r *http.Request, key string, required ...bool) (int, error)

func ParseInt16

func ParseInt16(r *http.Request, key string, required ...bool) (int16, error)

func ParseInt32

func ParseInt32(r *http.Request, key string, required ...bool) (int32, error)

func ParseInt64

func ParseInt64(r *http.Request, key string, required ...bool) (int64, error)

func ParseInt8

func ParseInt8(r *http.Request, key string, required ...bool) (int8, error)

func ParseString

func ParseString(r *http.Request, key string, required ...bool) (string, error)

func ParseUint

func ParseUint(r *http.Request, key string, required ...bool) (uint, error)

func ParseUint16

func ParseUint16(r *http.Request, key string, required ...bool) (uint16, error)

func ParseUint32

func ParseUint32(r *http.Request, key string, required ...bool) (uint32, error)

func ParseUint64

func ParseUint64(r *http.Request, key string, required ...bool) (uint64, error)

func ParseUint8

func ParseUint8(r *http.Request, key string, required ...bool) (uint8, error)

func Response

func Response(w http.ResponseWriter, status int, acceptType string, value interface{}, debug ...bool) error

func ResponseWithMarshaler

func ResponseWithMarshaler(
	w http.ResponseWriter,
	status int,
	contentType string,
	value interface{},
	marshal MarshalFunc,
	marshalIndent MarshalIndentFunc,
	debug ...bool) error

func TextResponse

func TextResponse(w http.ResponseWriter, status int, value string) error

func XMLResponse

func XMLResponse(w http.ResponseWriter, status int, value interface{}, debug ...bool) error

Types

type FormMarshaler

type FormMarshaler interface {
	MarshalForm() ([]byte, error)
}

type HandlerConnect

type HandlerConnect struct{}

func (HandlerConnect) Match

func (HandlerConnect) Match(r *http.Request) int

type HandlerDelete

type HandlerDelete struct{}

func (HandlerDelete) Match

func (HandlerDelete) Match(r *http.Request) int

type HandlerGet

type HandlerGet struct{}

func (HandlerGet) Match

func (HandlerGet) Match(r *http.Request) int

type HandlerHead

type HandlerHead struct{}

func (HandlerHead) Match

func (HandlerHead) Match(r *http.Request) int

type HandlerMatcher

type HandlerMatcher interface {
	Match(r *http.Request) int
}

type HandlerOptions

type HandlerOptions struct{}

func (HandlerOptions) Match

func (HandlerOptions) Match(r *http.Request) int

type HandlerPatch

type HandlerPatch struct{}

func (HandlerPatch) Match

func (HandlerPatch) Match(r *http.Request) int

type HandlerPost

type HandlerPost struct{}

func (HandlerPost) Match

func (HandlerPost) Match(r *http.Request) int

type HandlerPut

type HandlerPut struct{}

func (HandlerPut) Match

func (HandlerPut) Match(r *http.Request) int

type HandlerTrace

type HandlerTrace struct{}

func (HandlerTrace) Match

func (HandlerTrace) Match(r *http.Request) int

type MarshalFunc

type MarshalFunc func(interface{}) ([]byte, error)

type MarshalIndentFunc

type MarshalIndentFunc func(interface{}, string, string) ([]byte, error)

type Result

type Result struct {
	Response   *http.Response
	StatusCode int
	Data       []byte
	Error      error
}

func Get

func Get(url string) Result

func PostForm

func PostForm(url string, values url.Values) Result

func (Result) Ok

func (result Result) Ok() bool

func (Result) Status

func (result Result) Status() string

type ServeMux

type ServeMux struct {
	*http.ServeMux
}

func NewServeMux

func NewServeMux() *ServeMux

func (*ServeMux) ServeHTTP

func (mux *ServeMux) ServeHTTP(w http.ResponseWriter, r *http.Request)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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