httputil

package
v0.0.0-...-389bc3b Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var HTTPCodeOf = func(err error) int {
	return 599
}

HTTPCodeOf func

Functions

func DetectCode

func DetectCode(err error) int

DetectCode detect error return http status code

func DetectError

func DetectError(err error) (code int, desc string)

DetectError detect error return http status code and desc

func Error

func Error(w http.ResponseWriter, err error)

Error write error to http response writer

func HandleFunc

func HandleFunc(code int, data interface{}) func(w http.ResponseWriter, r *http.Request)

HandleFunc return handle func width http status code and response data

func HandleFuncWithCode

func HandleFuncWithCode(code int) func(w http.ResponseWriter, r *http.Request)

HandleFuncWithCode return handle func width http status code

func Reply

func Reply(w http.ResponseWriter, code int, data interface{})

Reply write http status code and data to http response writer

func ReplyErr

func ReplyErr(w http.ResponseWriter, code int, err string)

ReplyErr write error to http response writer with http status code

func ReplyWith

func ReplyWith(w http.ResponseWriter, code int, bodyType string, msg []byte)

ReplyWith write http status code and data to http response writer with request body type

func ReplyWithCode

func ReplyWithCode(w http.ResponseWriter, code int)

ReplyWithCode write http status code and data to http response writer

func ReplyWithStream

func ReplyWithStream(w http.ResponseWriter, code int, bodyType string, body io.Reader, bytes int64)

ReplyWithStream write http status code and data to http response writer with request body type

Types

type ErrorInfo

type ErrorInfo struct {
	Err  string
	Code int
}

ErrorInfo error info type

func NewError

func NewError(code int, err string) *ErrorInfo

NewError return error info obj

func (*ErrorInfo) Error

func (e *ErrorInfo) Error() string

Error implement error interface method

Jump to

Keyboard shortcuts

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