common

package
v0.0.0-...-1b17b00 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ReqBodyKey                  = "req-body"
	ResBodyKey                  = "res-body"
	TreePathDelimiter           = "."
	ASC               Direction = "ASC"
	DESC              Direction = "DESC"
)

Variables

This section is empty.

Functions

func Exists

func Exists(ctx context.Context, db *gorm.DB) (bool, error)

func FindOne

func FindOne(ctx context.Context, db *gorm.DB, opts QueryOptions, out interface{}) (bool, error)

func FindPage

func FindPage(ctx context.Context, db *gorm.DB, pp PaginationParam, opts QueryOptions, out interface{}) (int64, error)

func FromIsRootUser

func FromIsRootUser(ctx context.Context) bool

func FromRowLock

func FromRowLock(ctx context.Context) bool

func FromTraceID

func FromTraceID(ctx context.Context) string

func FromTrans

func FromTrans(ctx context.Context) (*gorm.DB, bool)

func FromUserID

func FromUserID(ctx context.Context) string

func FromUserToken

func FromUserToken(ctx context.Context) string

func GetBodyData

func GetBodyData(c *gin.Context) []byte

GetBodyData Get body data from context

func GetDB

func GetDB(ctx context.Context, defDB *gorm.DB) *gorm.DB

func GetToken

func GetToken(c *gin.Context) string

GetToken Get access token from header or query parameter

func NewIsRootUser

func NewIsRootUser(ctx context.Context) context.Context

func NewRowLock

func NewRowLock(ctx context.Context) context.Context

func NewTraceID

func NewTraceID(ctx context.Context, traceID string) context.Context

func NewTrans

func NewTrans(ctx context.Context, db *gorm.DB) context.Context

func NewUserCache

func NewUserCache(ctx context.Context, userCache UserCache) context.Context

func NewUserID

func NewUserID(ctx context.Context, userID string) context.Context

func NewUserToken

func NewUserToken(ctx context.Context, userToken string) context.Context

func NewXID

func NewXID() string

func ParseForm

func ParseForm(c *gin.Context, obj any) error

ParseForm Parse body form data to struct

func ParseJSON

func ParseJSON(c *gin.Context, obj any) error

ParseJSON Parse body json data to struct

func ParseQuery

func ParseQuery(c *gin.Context, obj any) error

ParseQuery Parse query parameter to struct

func ResError

func ResError(c *gin.Context, err error, status ...int)

func ResJSON

func ResJSON(c *gin.Context, status int, v any)

ResJSON Response json data with status code

func ResOK

func ResOK(c *gin.Context)

func ResPage

func ResPage(c *gin.Context, v any, pr *PaginationResult)

func ResSuccess

func ResSuccess(c *gin.Context, v any)

Types

type Direction

type Direction string

type OrderByParam

type OrderByParam struct {
	Field     string
	Direction Direction
}

type OrderByParams

type OrderByParams []OrderByParam

func (OrderByParams) ToSQL

func (a OrderByParams) ToSQL() string

type PaginationParam

type PaginationParam struct {
	Pagination bool `form:"-"`
	OnlyCount  bool `form:"-"`
	Current    int  `form:"page"`
	PageSize   int  `form:"pageSize" binding:"max=100"`
}

type PaginationResult

type PaginationResult struct {
	Total    int64 `json:"total"`
	Current  int   `json:"current"`
	PageSize int   `json:"pageSize"`
}

func WrapPageQuery

func WrapPageQuery(ctx context.Context, db *gorm.DB, pp PaginationParam, opts QueryOptions, out interface{}) (*PaginationResult, error)

type QueryOptions

type QueryOptions struct {
	SelectFields []string
	OmitFields   []string
	OrderFields  OrderByParams
}

type ResponseResult

type ResponseResult struct {
	Success bool          `json:"success"`
	Data    interface{}   `json:"data,omitempty"`
	Total   int64         `json:"total,omitempty"`
	Error   *errors.Error `json:"error,omitempty"`
}

type Trans

type Trans struct {
	DB *gorm.DB
}

func (*Trans) Exec

func (a *Trans) Exec(ctx context.Context, fn TransFunc) error

type TransFunc

type TransFunc func(context.Context) error

type UserCache

type UserCache struct {
	RoleIDs []string `json:"rids"`
}

UserCache Set user cache object

func FromUserCache

func FromUserCache(ctx context.Context) UserCache

func ParseUserCache

func ParseUserCache(s string) UserCache

func (UserCache) String

func (a UserCache) String() string

Jump to

Keyboard shortcuts

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