httpx

package
v1.0.34-withfile-v2 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RequestSuccessCode = 0
	RequestSuccessMsg  = "request successes."

	RequestBadCode = 400
	RequestBadMsg  = "request failed."
)
View Source
const (
	ApplicationJson = "application/json"
	ContentEncoding = "Content-Encoding"
	ContentSecurity = "X-Content-Security"
	ContentType     = "Content-Type"
	KeyField        = "key"
	SecretField     = "secret"
	TypeField       = "type"
	CryptionType    = 1
)
View Source
const (
	CodeSignaturePass = iota
	CodeSignatureInvalidHeader
	CodeSignatureWrongTime
	CodeSignatureInvalidToken
)

Variables

Functions

func Error

func Error(w http.ResponseWriter, err error)

func ErrorJson

func ErrorJson(w http.ResponseWriter, err error, v interface{})

func GetRemoteAddr

func GetRemoteAddr(r *http.Request) string

Returns the peer address, supports X-Forward-For

func Ok

func Ok(w http.ResponseWriter)

func OkJson

func OkJson(w http.ResponseWriter, v interface{})

func Parse

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

func ParseForm

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

Parses the form request.

func ParseHeader

func ParseHeader(headerValue string) map[string]string

func ParseJsonBody

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

Parses the post request which contains json in body.

func ParsePath

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

Parses the symbols reside in url path. Like http://localhost/bag/:name

func SetErrorHandler

func SetErrorHandler(handler func(error) (int, interface{}))

func WriteJson

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

Types

type ResponseError

type ResponseError struct {
	Code int64       `json:"code"`
	Msg  string      `json:"msg"`
	Data interface{} `json:"data"`
}

func NewResponseError

func NewResponseError(option ...ResponseErrorOption) *ResponseError

func (ResponseError) Error

func (e ResponseError) Error() string

func (*ResponseError) Is

func (e *ResponseError) Is(target error) bool

type ResponseErrorOption

type ResponseErrorOption func(responseError *ResponseError)

func CodeOption

func CodeOption(code int64) ResponseErrorOption

func DataOption

func DataOption(data interface{}) ResponseErrorOption

func MsgOption

func MsgOption(msg string) ResponseErrorOption

type Router

type Router interface {
	http.Handler
	Handle(method string, path string, handler http.Handler) error
	SetNotFoundHandler(handler http.Handler)
	SetNotAllowedHandler(handler http.Handler)
}

Jump to

Keyboard shortcuts

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