jgin

package
v0.0.0-...-3f91146 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ERROR   = 7
	SUCCESS = 0
)

Variables

This section is empty.

Functions

func Fail

func Fail(c *gin.Context)

func FailWithDetailed

func FailWithDetailed(data interface{}, message string, c *gin.Context)

func FailWithMessage

func FailWithMessage(message string, c *gin.Context)

func GinMustBind

func GinMustBind(c *gin.Context, obj interface{}) error

GinMustBind 示例:解析请求参数

func Ok

func Ok(c *gin.Context)

func OkWithData

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

func OkWithDetailed

func OkWithDetailed(data interface{}, message string, c *gin.Context)

func OkWithMessage

func OkWithMessage(message string, c *gin.Context)

func RegBinding

func RegBinding(mime string, b binding.Binding)

RegBinding 注册请求与 model 的解析器

func RegBindingHandler

func RegBindingHandler(h BindingHandler)

func Result

func Result(code int, data interface{}, msg string, c *gin.Context)

func ResultErr

func ResultErr(data interface{}, e error, c *gin.Context)

ResultErr 处理错误,如果错误为nil,则返回成功,否则按照错误类型返回

Types

type BindingHandler

type BindingHandler func(context2 *gin.Context, req any) error

type ErrorWithCode

type ErrorWithCode interface {
	ErrorCode() int
}

type ErrorWithHttpCode

type ErrorWithHttpCode interface {
	ErrorHttpCode() int
}

type IdExt

type IdExt interface {
	GetID() uint
	GetVal() interface{}
}

type IdText

type IdText struct {
	ID   uint   `json:"id" form:"id"`
	Text string `json:"text" form:"text"`
}

type JDates

type JDates string

func (JDates) Date

func (J JDates) Date() time.Time

func (JDates) DateLocal

func (J JDates) DateLocal() time.Time

type JIDs

type JIDs string

JIDs 用逗号分隔的整数列表

func (*JIDs) FromID

func (id *JIDs) FromID(ids []uint)

func (*JIDs) FromInt

func (id *JIDs) FromInt(ids []int)

func (*JIDs) FromInt64

func (id *JIDs) FromInt64(ids []int64)

func (*JIDs) FromTag

func (id *JIDs) FromTag(elems []string)

func (JIDs) GetID

func (id JIDs) GetID() []uint

func (JIDs) GetIDUnique

func (id JIDs) GetIDUnique() []uint

func (JIDs) GetInt

func (id JIDs) GetInt() []int

func (JIDs) GetTag

func (id JIDs) GetTag() []string

func (JIDs) GetTagUnique

func (id JIDs) GetTagUnique() []string

type KeyText

type KeyText struct {
	Key  string `json:"key"`
	Text string `json:"text"`
}

type PageReq

type PageReq struct {
	Page     int `form:"page" json:"page" query:"page"  example:"1"`             // 页号,从1开始
	PageSize int `form:"pageSize" json:"pageSize" query:"pageSize" example:"10"` // 分页大小
}

PageReq 分页

func (*PageReq) FixPageSize

func (P *PageReq) FixPageSize(num, size int)

type PageResp

type PageResp struct {
	Page      int `json:"page" example:"1"`      // 页号,从1开始
	PageSize  int `json:"pageSize" example:"10"` // 分页大小
	Total     int `json:"total" example:"51"`    // 总记录数
	TotalPage int `json:"totalPage" example:"6"` // 总页数
}

func (*PageResp) SetPageSize

func (P *PageResp) SetPageSize(num, size int, cnt int64) (offset int)

SetPageSize 设置页码数,并返回 offset ,如果 offset == -1 表示不可用

type ReqWithCtx

type ReqWithCtx struct {
	// contains filtered or unexported fields
}

ReqWithCtx 上下文环境

func (*ReqWithCtx) GetCtx

func (R *ReqWithCtx) GetCtx() context.Context

func (*ReqWithCtx) GetCtxValue

func (R *ReqWithCtx) GetCtxValue(k interface{}) interface{}

func (*ReqWithCtx) SetCtx

func (R *ReqWithCtx) SetCtx(ctx context.Context)

func (*ReqWithCtx) SetCtxValue

func (R *ReqWithCtx) SetCtxValue(k, v interface{})

type ReqWithIP

type ReqWithIP struct {
	// contains filtered or unexported fields
}

ReqWithIP 客户端 ip

func (*ReqWithIP) GetIP

func (R *ReqWithIP) GetIP() string

func (*ReqWithIP) SetIP

func (R *ReqWithIP) SetIP(ip string)

type ReqWithNow

type ReqWithNow struct {
	// contains filtered or unexported fields
}

ReqWithNow 统一业务时间点

func (*ReqWithNow) GetNow

func (R *ReqWithNow) GetNow() time.Time

func (*ReqWithNow) SetNow

func (R *ReqWithNow) SetNow(now time.Time)

type Response

type Response struct {
	Code int         `json:"code"`
	Data interface{} `json:"data,omitempty"`
	Msg  string      `json:"msg"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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