utils

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cors added in v1.1.0

func Cors(cfg *utils.Config) gin.HandlerFunc

func GetSub added in v1.0.5

func GetSub(ctx context.Context, cfg *wcmd_utils.Config) string

func GetTid added in v1.0.5

func GetTid(ctx context.Context, cfg *wcmd_utils.Config) string

func GetTxFromContext added in v1.0.1

func GetTxFromContext(ctx context.Context) (*gorm.DB, error)

func InstanceMetric added in v1.1.1

func InstanceMetric(port string, host string, engine *gin.Engine) *gin.Engine

func MapPtrSlice added in v1.1.0

func MapPtrSlice[T any, U any](items []*T, mapper func(*T) *U) []*U

[]*T -> []*U

func SaveRequestContext

func SaveRequestContext(ctx context.Context, reqCtx *RequestContext, cfg *wcmd_utils.Config) context.Context

func ShutdownServer added in v1.0.5

func ShutdownServer(ctx context.Context, engine http.Handler, host string, port string)

Types

type Helper added in v1.1.1

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

func NewHelper added in v1.1.1

func NewHelper(cfg *utils.Config) *Helper

func (*Helper) GetInfo added in v1.1.1

func (h *Helper) GetInfo(c *gin.Context) (ipAddress, userAgent, locale, timezone string)

type PaginationRequest added in v1.0.5

type PaginationRequest struct {
	Page   int    `form:"page" binding:"omitempty,min=1"`
	Limit  int    `form:"limit" binding:"omitempty,min=1,max=100"`
	Search string `form:"search"`
	Sort   string `form:"sort"`
	Order  string `form:"order"`
}

func (*PaginationRequest) GetLimit added in v1.0.5

func (p *PaginationRequest) GetLimit() int

func (*PaginationRequest) GetNextPage added in v1.0.5

func (p *PaginationRequest) GetNextPage(total int64) int

func (*PaginationRequest) GetOffset added in v1.0.5

func (p *PaginationRequest) GetOffset() int

func (*PaginationRequest) GetOrder added in v1.0.5

func (p *PaginationRequest) GetOrder(defaultOrder string) string

func (*PaginationRequest) GetPage added in v1.0.5

func (p *PaginationRequest) GetPage() int

func (*PaginationRequest) GetPrevPage added in v1.0.5

func (p *PaginationRequest) GetPrevPage() int

func (*PaginationRequest) GetSort added in v1.0.5

func (p *PaginationRequest) GetSort(defaultSort string) string

func (*PaginationRequest) GormScope added in v1.0.5

func (p *PaginationRequest) GormScope() func(db *gorm.DB) *gorm.DB

func (*PaginationRequest) HasNext added in v1.0.5

func (p *PaginationRequest) HasNext(total int64) bool

func (*PaginationRequest) HasPrev added in v1.0.5

func (p *PaginationRequest) HasPrev() bool

func (*PaginationRequest) Normalize added in v1.0.5

func (p *PaginationRequest) Normalize()

func (*PaginationRequest) ToPaginationResponse added in v1.0.5

func (p *PaginationRequest) ToPaginationResponse(total int64) PaginationResponse

func (*PaginationRequest) TotalPages added in v1.0.5

func (p *PaginationRequest) TotalPages(total int64) int

type PaginationResponse added in v1.0.5

type PaginationResponse struct {
	Page       int   `json:"page"`
	Limit      int   `json:"limit"`
	Total      int64 `json:"total"`
	TotalPages int   `json:"totalPages"`
	HasNext    bool  `json:"hasNext"`
	HasPrev    bool  `json:"hasPrev"`
	NextPage   int   `json:"nextPage,omitempty"`
	PrevPage   int   `json:"prevPage,omitempty"`
}

type RequestContext added in v1.0.5

type RequestContext struct {
	Tid string
	Sub string
}

func GetRequestContext

func GetRequestContext(ctx context.Context, cfg *wcmd_utils.Config) *RequestContext

func NewRequestContext added in v1.0.5

func NewRequestContext(sub, tid string) *RequestContext

func NewRequestContextFull added in v1.0.5

func NewRequestContextFull(sub, tid string) *RequestContext

type TransactionError added in v1.0.1

type TransactionError struct {
	OriginalError error
	RollbackError error
}

func (*TransactionError) Error added in v1.0.1

func (e *TransactionError) Error() string

type TxManager added in v1.0.1

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

func NewTxManager added in v1.0.1

func NewTxManager(db *gorm.DB) *TxManager

func (*TxManager) WithinTransaction added in v1.0.1

func (t *TxManager) WithinTransaction(ctx context.Context, fn func(ctx context.Context) error) error

Jump to

Keyboard shortcuts

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