bit

package module
v1.0.1-beta Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2021 License: MIT Imports: 5 Imported by: 0

README

Gin Bit

Use gorm to quickly generate the function API of the gin framework

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bind

func Bind(handlerFn interface{}) gin.HandlerFunc

Bind The binding routing function returns the result uniformly

Params:
 handlerFn: func(c *gin.Context) interface{}
Mapped return:
 (string) => 200 {"error":0,"msg":<this string value>}
 (error) => 200 {"error":1,"msg":<this error msg, for example err.Error()>}
 (default) => 200 {"error":0,"data":<interface{}>}
Custom error code: c.Set("code", 1000)

func Mixed

func Mixed(c *gin.Context, operator ...Operator)

Mixed define mixed operations

Params:
 c: *gin.Context
 operator: mixed operations

Types

type Bit

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

Bit a tools

func Initialize

func Initialize(db *gorm.DB) *Bit

Initialize initialize tool set

Params:
 db: *gorm.DB

func (*Bit) Crud

func (x *Bit) Crud(model interface{}, options ...CrudOption) *Crud

Crud create CRUD functions

Params:
 model: model name
 options: crud option

type Conditions

type Conditions [][]interface{}

Conditions array condition definition

func (Conditions) GetConditions

func (c Conditions) GetConditions() Conditions

GetConditions get array condition definition

type Crud

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

func (*Crud) Add

func (x *Crud) Add(c *gin.Context) interface{}

Add general definition of create data request

func (*Crud) Delete

func (x *Crud) Delete(c *gin.Context) interface{}

Delete general definition of delete data request

func (*Crud) Edit

func (x *Crud) Edit(c *gin.Context) interface{}

Edit general definition of edit data request

func (*Crud) Get

func (x *Crud) Get(c *gin.Context) interface{}

Get general definition of get data request

func (*Crud) GetMixed

func (x *Crud) GetMixed(c *gin.Context) *mixed

GetMixed get mixed vars

func (*Crud) Lists

func (x *Crud) Lists(c *gin.Context) interface{}

Lists general definition of page data

func (*Crud) OriginLists

func (x *Crud) OriginLists(c *gin.Context) interface{}

OriginLists general definition of list request

type CrudOption

type CrudOption func(*Crud)

CrudOption crud option

func SetOrders

func SetOrders(orders Orders) CrudOption

SetOrders set global ordering

Params:
 orders: map[string]string

type DeleteBody

type DeleteBody struct {
	Id         interface{} `json:"id" binding:"required_without=Conditions"`
	Conditions `json:"where" binding:"required_without=Id,gte=0,dive,len=3,dive,required"`
}

DeleteBody general definition of delete body

func (*DeleteBody) GetId

func (x *DeleteBody) GetId() interface{}

GetId get id

type EditBody

type EditBody struct {
	Id         interface{} `json:"id" binding:"required_without=Conditions"`
	Conditions `json:"where" binding:"required_without=Id,gte=0,dive,len=3,dive,required"`
	Switch     *bool `json:"switch"`
}

EditBody general definition of edit body

func (*EditBody) GetId

func (x *EditBody) GetId() interface{}

GetId get id

type GetBody

type GetBody struct {
	Id         interface{} `json:"id" binding:"required_without=Conditions"`
	Conditions `json:"where" binding:"required_without=Id,gte=0,dive,len=3,dive,required"`
	Orders     `json:"order" binding:"omitempty,gte=0,dive,keys,endkeys,oneof=asc desc,required"`
}

GetBody general definition of get body

func (*GetBody) GetId

func (x *GetBody) GetId() interface{}

GetId get id

type ListsBody

type ListsBody struct {
	Pagination `json:"page" binding:"required"`
	Conditions `json:"where" binding:"omitempty,gte=0,dive,len=3,dive,required"`
	Orders     `json:"order" binding:"omitempty,gte=0,dive,keys,endkeys,oneof=asc desc,required"`
}

ListsBody general definition of page body

type Operator

type Operator func(*mixed)

Operator mixed operations

func Query

func Query(fn func(tx *gorm.DB) *gorm.DB) Operator

Query query custom extension

Params:
 fn: func(tx *gorm.DB) *gorm.DB

func SetBody

func SetBody(body interface{}) Operator

SetBody define the custom request body

Scenes:
 OriginLists,Lists,Get,Delete: they need to embed OriginListsBody, ListsBody, GetBody, DeleteBody
 Add,Edit: useless

func SetData

func SetData(data interface{}) Operator

SetData data with different meanings

Scenes:
 OriginLists,Lists,Get: the specified gorm model, used to query and return data
 Add: used to create custom data
 Edit: used to customize update data
 Delete: useless

func TxNext

func TxNext(fn func(tx *gorm.DB, args ...interface{}) error) Operator

TxNext transaction custom extension

Params:
 fn: func(tx *gorm.DB, args ...interface{}) error

type Orders

type Orders map[string]string

Orders order definition

func (Orders) GetOrders

func (c Orders) GetOrders() Orders

GetOrders get order definition

type OriginListsBody

type OriginListsBody struct {
	Conditions `json:"where" binding:"omitempty,gte=0,dive,len=3,dive,required"`
	Orders     `json:"order" binding:"omitempty,gte=0,dive,keys,endkeys,oneof=asc desc,required"`
}

OriginListsBody general definition of list body

type Pagination

type Pagination struct {
	Index int `json:"index" binding:"gt=0,number,required"`
	Limit int `json:"limit" binding:"gt=0,number,required"`
}

Pagination page properties

Index: page number
Limit: number of pages

func (Pagination) GetPagination

func (x Pagination) GetPagination() Pagination

GetPagination get page properties

Jump to

Keyboard shortcuts

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