httputil

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusGracefulQuit = 570 // 停止服务中(重启中)
	StatusOverload     = 571 // 过载保护阶段(处理部分请求,其余返回 571 重试码)
	StatusAbnormal     = 572 // 认为自身工作不正常时,比如长时间没法拿到数据
	StatusOutOfQuota   = 573 // 客户端请求超出限制,拒绝请求报573
)

Variables

View Source
var (
	ErrGracefulQuit         = NewError(StatusGracefulQuit, "graceful quit")
	ErrOverload             = NewError(StatusOverload, "overload")
	ErrOutOfConcurrentQuota = NewError(StatusOutOfQuota, "out of concurrent quota")
	ErrOutOfRequestQuota    = NewError(StatusOutOfQuota, "out of request quota")
	ErrOutOfFlowQuota       = NewError(StatusOutOfQuota, "out of flow quota")
)

Functions

func DetectCode

func DetectCode(err error) int

func DetectError

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

func DetectErrorCode

func DetectErrorCode(err error) string

func Error

func Error(w http.ResponseWriter, err error)

func ErrorWithCT

func ErrorWithCT(w http.ResponseWriter, err error, contentType string)

func Flusher

func Flusher(w http.ResponseWriter) (f http.Flusher, ok bool)

func GetCloseNotifier

func GetCloseNotifier(w http.ResponseWriter) (cn http.CloseNotifier, ok bool)

deprecated: use http.Request.Context()

func GetCloseNotifierSafe

func GetCloseNotifierSafe(w http.ResponseWriter) http.CloseNotifier

deprecated: use http.Request.Context()

func GetHijacker

func GetHijacker(w http.ResponseWriter) (hj http.Hijacker, ok bool)

func HijackClose

func HijackClose(xl *xlog.Logger, w http.ResponseWriter)

强制断开请求连接

func NewCodeError

func NewCodeError(code int) error

func Reply

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

func ReplyErr

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

func ReplyError

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

func ReplyErrorCode

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

func ReplyWith

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

func ReplyWithCode

func ReplyWithCode(w http.ResponseWriter, code int)

func ReplyWithStream

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

Types

type Errno

type Errno int

func (Errno) Error

func (r Errno) Error() string

type ErrorInfo

type ErrorInfo struct {
	Err     string
	Code    int
	ErrCode string
}

func NewError

func NewError(code int, err string) *ErrorInfo

func NewErrorCode

func NewErrorCode(code int, errCode, err string) *ErrorInfo

func (*ErrorInfo) Error

func (e *ErrorInfo) Error() string

func (ErrorInfo) ErrorCode

func (e ErrorInfo) ErrorCode() string

func (ErrorInfo) HttpCode

func (e ErrorInfo) HttpCode() int

func (*ErrorInfo) WithMsg

func (e *ErrorInfo) WithMsg(err string) *ErrorInfo

type ErrorRet

type ErrorRet struct {
	Error     string `json:"error"`
	ErrorCode string `json:"error_code,omitempty"`
}

type RequestCanceler

type RequestCanceler interface {
	CancelRequest(req *http.Request)
}

func GetRequestCanceler

func GetRequestCanceler(tp http.RoundTripper) (rc RequestCanceler, ok bool)

deprecated: use http.Request.WithContext()

Jump to

Keyboard shortcuts

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