http

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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
}

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) 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) 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