ctx

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handle

func Handle(h HandlerFunc) gin.HandlerFunc

Types

type Context

type Context struct {
	*gin.Context
}

func (*Context) BadRequest

func (c *Context) BadRequest(err error)

func (*Context) BuildQuery

func (c *Context) BuildQuery(structP any) (string, []any, error)

BuildQuery build and validate query param to struct, struct param is pointer form tag is query param and json tag is table column name

type Temp struct {
	Name string `form:"name" json:"name"`
	ID   []uint `form:"id[]" json:"id"`
}

query url ?name=tom&id[]=1&id[]=2 will generate ("name = ? AND id IN ?", "tom", []uint(1,2))

created_at is a special tag and every table must have created_at column see `service/bill/details/list.go` for more example

func (*Context) GetIDList

func (c *Context) GetIDList() (IDList, error)

func (*Context) InternalErr

func (c *Context) InternalErr(err error)

func (*Context) Paging

func (c *Context) Paging() (Paging, error)

func (*Context) Success

func (c *Context) Success()

func (*Context) SuccessWith

func (c *Context) SuccessWith(r Response)

type HandlerFunc

type HandlerFunc func(c *Context)

type IDList

type IDList struct {
	IDS []uint64 `json:"ids" validate:"required"`
}

type Paging

type Paging struct {
	Page int `form:"page"`
	Size int `form:"size" validate:"max=100"`
}

type Response

type Response struct {
	Msg   string `json:"msg"`
	Data  any    `json:"data,omitempty"`
	Count int64  `json:"count,omitempty"`
}

Jump to

Keyboard shortcuts

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