httpx

package
v0.0.20 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2022 License: MIT Imports: 16 Imported by: 1

Documentation

Index

Constants

View Source
const (
	//最大打印gin resp_body长度  1mb
	MAX_PRINT_GIN_RESP_BODY_LEN = 1048576
	//最大打印gin req_body 长度
	MAX_PRINT_GIN_REQ_BODY_LEN = 1048576
)

Variables

View Source
var (
	GET    http_method = "GET"
	POST   http_method = "POST"
	DELETE http_method = "DELETE"
	PUT    http_method = "PUT"
)

Functions

func AppendReqHeadLog

func AppendReqHeadLog(name ...string) gin.HandlerFunc

追加请求头日志

func Cors

func Cors() gin.HandlerFunc

处理跨域请求,支持options访问

func DisableReqBodyLog

func DisableReqBodyLog() gin.HandlerFunc

禁用请求体日志

func DisableRespBodyLog

func DisableRespBodyLog() gin.HandlerFunc

禁用返回体日志

func EnableGinLog

func EnableGinLog() gin.HandlerFunc

gin请求日志中间件 todo req_id

func Fail

func Fail(c *gin.Context)

func FailWithData

func FailWithData(c *gin.Context, ResData interface{})

func FailWithDetailed

func FailWithDetailed(c *gin.Context, ResCode ResCode, ResMsg interface{}, ResData interface{})

func FailWithMessage

func FailWithMessage(c *gin.Context, ResMsg interface{})

func Get

func Get(url string) ([]byte, error)

func GetGinContextReqId

func GetGinContextReqId(c *gin.Context) string

func HttpStringResult

func HttpStringResult(result []byte, err error) (string, error)

转化http返回值为string

func Middleware_SetReqId added in v0.0.19

func Middleware_SetReqId() gin.HandlerFunc

func NewGin

func NewGin() *gin.Engine

func NewHttpClient

func NewHttpClient(method http_method, url string, req_body []byte) *http_client

func NewHttpClientWithFile

func NewHttpClientWithFile(url string, filename string, fh io.Reader, size int64) (*http_client, error)

todo 提取file部分代码

func NewHttpClientWithJson

func NewHttpClientWithJson(method http_method, url string, req_body interface{}) (*http_client, error)

func NoFindResult

func NoFindResult(c *gin.Context)

func Ok

func Ok(c *gin.Context)

func OkDetailed

func OkDetailed(c *gin.Context, ResMsg interface{}, ResData interface{})

func OkWithData

func OkWithData(c *gin.Context, ResData interface{})

func OkWithMessage

func OkWithMessage(c *gin.Context, ResMsg interface{})

func Post

func Post(url, contentType string, req_body []byte) ([]byte, error)

func PostWithForm

func PostWithForm(url string, req_body map[string]string) (result []byte, err error)

func PostWithJson

func PostWithJson(url string, req_body interface{}) (result []byte, err error)

func RecoverHandler

func RecoverHandler(c *gin.Context)

panic处理

func Result

func Result(c *gin.Context, ResCode ResCode, ResMsg interface{}, ResData interface{})

func RewriteReqBody

func RewriteReqBody(c *gin.Context, body []byte)

重写请求体内容

Types

type BasePageModel

type BasePageModel struct {
	Data  interface{} `json:"data"`
	Count int64       `json:"count"`
}

type ResCode

type ResCode int
const (
	SUCCESS ResCode = 0
	//服务器内部逻辑异常
	ERROR ResCode = 500
	//请求参数检查错误
	ParamterError ResCode = 501
	NoFind        ResCode = 404
	//登陆异常
	LoginFailure ResCode = 401
	//鉴权失败
	Unauthorized ResCode = 402
)

type Response

type Response struct {
	Code ResCode     `json:"code"`
	Data interface{} `json:"data"`
	Msg  interface{} `json:"msg"`
}

Jump to

Keyboard shortcuts

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