util

package
v10.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2023 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

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

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

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

Get access token from header or query parameter

func MustNewUUID

func MustNewUUID() string

The function generates a new UUID and panics if there is an error.

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

The function "NewXID" generates a new unique identifier (XID) and returns it as a string.

func ParseForm

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

Parse body form data to struct

func ParseJSON

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

Parse body json data to struct

func ParseQuery

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

Parse query parameter to struct

func RandomizedIPAddr

func RandomizedIPAddr() string

The RandomizedIPAddr function generates a random IP address.

func ResError

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

func ResJSON

func ResJSON(c *gin.Context, status int, v interface{})

Response json data with status code

func ResOK

func ResOK(c *gin.Context)

func ResPage

func ResPage(c *gin.Context, v interface{}, pr *PaginationResult)

func ResSuccess

func ResSuccess(c *gin.Context, v interface{})

func Run

func Run(ctx context.Context, handler func(ctx context.Context) (func(), error)) error

The Run function sets up a signal handler and executes a handler function until a termination signal is received.

Types

type Direction

type Direction string
const (
	ASC  Direction = "ASC"
	DESC Direction = "DESC"
)

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:"current"`
	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"`
}

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