http

package
v0.10.13 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetRandomUserAgent added in v0.10.1

func GetRandomUserAgent() string

GetRandomUserAgent 获取随机User-Agent

func IsValidUrl added in v0.10.1

func IsValidUrl(str string) bool

IsValidUrl 是否是有效的url

Types

type Client

type Client struct {
	Debug     bool                   // 是否开启debug模式
	Url       string                 // 请求地址
	Params    map[string]string      // 请求参数
	Header    map[string]string      // 请求头
	Form      map[string]interface{} // 表单参数
	UserAgent string                 // User-Agent
	Json      []byte                 // json参数
}

func (*Client) Get

func (Client *Client) Get() ([]byte, error)

Get get请求返回[]byte

func (*Client) Post

func (Client *Client) Post() ([]byte, error)

Post post请求返回[]byte

type GinHandle added in v0.0.4

type GinHandle struct{}

func (*GinHandle) DefaultQuery added in v0.0.4

func (*GinHandle) DefaultQuery(c *gin.Context, key string, defaultValue string) string

DefaultQuery 获取get参数,如果没有则返回默认值 例如:/user?name=xxx => DefaultQuery(c, "name", "default")

func (*GinHandle) FormFile added in v0.0.9

func (*GinHandle) FormFile(c *gin.Context, key string) (*multipart.FileHeader, error)

FormFile 获取上传文件 例如:FormFile(c, "file")

func (*GinHandle) Param added in v0.0.4

func (*GinHandle) Param(c *gin.Context, key string) string

Param 获取路由参数 例如:/user/:name => Param(c, "name")

func (*GinHandle) Query added in v0.0.4

func (*GinHandle) Query(c *gin.Context, key string) string

Query 获取get参数 例如:/user?name=xxx => Query(c, "name")

func (*GinHandle) RequestFormFile added in v0.5.0

func (*GinHandle) RequestFormFile(c *gin.Context, key string) (multipart.File, *multipart.FileHeader, error)

RequestFormFile 获取上传文件 例如:RequestFormFile(c, "file")

func (*GinHandle) RetuenHTML added in v0.5.3

func (*GinHandle) RetuenHTML(c *gin.Context, name string, data interface{})

RetuenHTML 返回html 例如:RetuenHTML(c, "index.html", data)

func (*GinHandle) RetuenOk added in v0.0.5

func (*GinHandle) RetuenOk(c *gin.Context, data interface{})

RetuenOk 返回成功json 例如:RetuenOk(c, data) => ReturnJSON(c, http.StatusOK, respx.Succ(data))

func (*GinHandle) ReturnErr added in v0.0.5

func (*GinHandle) ReturnErr(c *gin.Context, r *replyx.T)

ReturnErr 返回错误json 例如:ReturnErr(c, respx.ParamErrT.ToPt()) => ReturnJSON(c, http.StatusBadRequest, respx.ParamErrT.ToPt())

func (*GinHandle) ReturnHTML added in v0.10.7

func (*GinHandle) ReturnHTML(c *gin.Context, name string, data interface{})

ReturnHTML 返回html 例如:ReturnHTML(c, "index.html", data)

func (*GinHandle) ReturnJSON added in v0.0.5

func (*GinHandle) ReturnJSON(c *gin.Context, code int, data interface{})

ReturnJSON 返回json 例如:ReturnJSON(c, http.StatusOK, respx.Succ(data))

func (*GinHandle) ReturnOk added in v0.10.7

func (*GinHandle) ReturnOk(c *gin.Context, data interface{})

ReturnOk 返回成功json 例如:ReturnOk(c, data) => ReturnJSON(c, http.StatusOK, respx.Succ(data))

func (*GinHandle) ReturnStatusOKErr added in v0.9.5

func (*GinHandle) ReturnStatusOKErr(c *gin.Context, r *replyx.T)

ReturnStatusOKErr 返回错误json(http=200) 例如:ReturnStatusOKErr(c, respx.ParamErrT.ToPt()) => ReturnJSON(c, http.StatusOK, respx.ParamErrT.ToPt())

func (*GinHandle) ShouldBind added in v0.0.4

func (*GinHandle) ShouldBind(c *gin.Context, s interface{}) error

ShouldBind Get绑定到结构体 例如:

type DemoGetReq struct {
	Id int `form:"id"` // 必须有form标签
}

var r req.DemoGetReq /user?name=xxx => ShouldBind(c, &r)

func (*GinHandle) ShouldBindJSON added in v0.0.4

func (*GinHandle) ShouldBindJSON(c *gin.Context, s interface{}) error

ShouldBindJSON Post绑定到结构体 例如:

type DemoPostReq struct {
	Id int `json:"id"` // 必须有json标签,application/json
}

var r req.DemoPostReq /user => ShouldBindJSON(c, &r)

func (*GinHandle) ShouldBindUri added in v0.1.5

func (*GinHandle) ShouldBindUri(c *gin.Context, s interface{}) error

ShouldBindUri 路由参数绑定到结构体 例如:

type DemoUriReq struct {
	Id int `uri:"id"` // 必须有uri标签
}

var r req.DemoUriReq /user/:id => ShouldBindUri(c, &r)

Jump to

Keyboard shortcuts

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