Documentation
¶
Index ¶
- Constants
- func ConvertTimestampToTime(timestamp string) *time.Time
- func ConvertToFloat(value string) float64
- func Exists(ctx context.Context, db *gorm.DB) (bool, error)
- func FindOne(ctx context.Context, db *gorm.DB, opts QueryOptions, out interface{}) (bool, error)
- func FindPage(ctx context.Context, db *gorm.DB, pp PaginationParam, opts QueryOptions, ...) (int64, error)
- func FromClientIP(ctx context.Context) string
- func FromIsRootUser(ctx context.Context) bool
- func FromRowLock(ctx context.Context) bool
- func FromTenant(ctx context.Context) string
- func FromTraceID(ctx context.Context) string
- func FromTrans(ctx context.Context) (*gorm.DB, bool)
- func FromUserAgent(ctx context.Context) string
- func FromUserID(ctx context.Context) string
- func FromUserToken(ctx context.Context) string
- func FromUsername(ctx context.Context) string
- func GetBodyData(c *gin.Context) []byte
- func GetDB(ctx context.Context, defDB *gorm.DB) *gorm.DB
- func GetToken(c *gin.Context) string
- func IsEmptyOrBlank(value string) bool
- func IsNilOrEmpty(value *string) bool
- func MustNewUUID() string
- func NewClientIP(ctx context.Context, ip string) context.Context
- func NewIsRootUser(ctx context.Context) context.Context
- func NewRowLock(ctx context.Context) context.Context
- func NewTenant(ctx context.Context, tenant string) context.Context
- func NewTraceID(ctx context.Context, traceID string) context.Context
- func NewTrans(ctx context.Context, db *gorm.DB) context.Context
- func NewUserAgent(ctx context.Context, userAgent string) context.Context
- func NewUserCache(ctx context.Context, userCache UserCache) context.Context
- func NewUserID(ctx context.Context, userID string) context.Context
- func NewUserToken(ctx context.Context, userToken string) context.Context
- func NewUsername(ctx context.Context, username string) context.Context
- func NewXID() string
- func ParseDurationString(durationStr string) (time.Duration, error)
- func ParseForm(c *gin.Context, obj interface{}) error
- func ParseJSON(c *gin.Context, obj interface{}) error
- func ParseQuery(c *gin.Context, obj interface{}) error
- func RandomizedIPAddr() string
- func ResError(c *gin.Context, err error, status ...int)
- func ResJSON(c *gin.Context, status int, v interface{})
- func ResOK(c *gin.Context)
- func ResPage(c *gin.Context, v interface{}, pr *PaginationResult)
- func ResSuccess(c *gin.Context, v interface{})
- func Run(ctx context.Context, handler func(ctx context.Context) (func(), error)) error
- func SoftDelete(ctx context.Context, db *gorm.DB, id string) error
- func String(s *string) string
- func StringPtr(s string) *string
- func TimeConvert(startTimeStr string, endTimeStr string) (time.Time, time.Time, error)
- type Direction
- type OrderByParam
- type OrderByParams
- type PaginationParam
- type PaginationResult
- type QueryOptions
- type ResponseResult
- type Trans
- type TransFunc
- type UserCache
Constants ¶
const ( ReqBodyKey = "req-body" ResBodyKey = "res-body" TreePathDelimiter = "." )
Variables ¶
This section is empty.
Functions ¶
func ConvertTimestampToTime ¶
ConvertTimestampToTime converts a string timestamp in milliseconds to a time.Time object
func ConvertToFloat ¶
func FindPage ¶
func FindPage(ctx context.Context, db *gorm.DB, pp PaginationParam, opts QueryOptions, out interface{}) (int64, error)
func FromClientIP ¶
func FromIsRootUser ¶
func FromRowLock ¶
func FromTenant ¶
func FromTraceID ¶
func FromUserAgent ¶
func FromUserID ¶
func FromUserToken ¶
func FromUsername ¶
func IsEmptyOrBlank ¶
IsEmptyOrBlank The function is used to check if a string is empty or if it contains only whitespace characters.
func IsNilOrEmpty ¶
IsNilOrEmpty The function is used to check if a string pointer is nil or if the string it points to is empty.
func MustNewUUID ¶
func MustNewUUID() string
The function generates a new UUID and panics if there is an error.
func NewXID ¶
func NewXID() string
The function "NewXID" generates a new unique identifier (XID) and returns it as a string.
func ParseDurationString ¶
ParseDurationString 将类似 "1s", "1m", "1h", "1d", "5w", "6y" 的字符串转换为 time.Duration
func ParseQuery ¶
Parse query parameter to struct
func RandomizedIPAddr ¶
func RandomizedIPAddr() string
The RandomizedIPAddr function generates a random IP address.
func ResPage ¶
func ResPage(c *gin.Context, v interface{}, pr *PaginationResult)
func ResSuccess ¶
func Run ¶
The Run function sets up a signal handler and executes a handler function until a termination signal is received.
func SoftDelete ¶
SoftDelete performs a logical delete by setting deleted to the record's id and deleted_at to the current time. The db parameter should already include the model scope (e.g., from GetXxxDB) with the deleted='0' filter applied. This ensures consistency across all tables that follow the deleted/deleted_at convention.
Types ¶
type OrderByParam ¶
type OrderByParams ¶
type OrderByParams []OrderByParam
func (OrderByParams) ToSQL ¶
func (a OrderByParams) ToSQL() string
type PaginationParam ¶
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 UserCache ¶
type UserCache struct {
RoleIDs []string `json:"rids"`
Username string `json:"username"`
Tenant string `json:"tenant"`
}
Set user cache object