utils

package
v0.0.0-...-9bc178f Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ENV_CONFIG_CACHE_SIZE    = "CONFIG_CACHE_SIZE"
	ENV_CONFIG_CACHE_EXPIRED = "CONFIG_CACHE_EXPIRED"
)

Variables

This section is empty.

Functions

func CheckValue

func CheckValue(db *gorm.DB, key, defaultValue, format string, autoload, public bool)

func GetBoolEnv

func GetBoolEnv(key string) bool

func GetBoolValue

func GetBoolValue(db *gorm.DB, key string) bool

func GetEnv

func GetEnv(key string) string

func GetFloatEnv

func GetFloatEnv(key string) float64

func GetFloatEnvWithDefault

func GetFloatEnvWithDefault(key string, defaultValue float64) float64

GetFloatEnvWithDefault gets float environment variable with default value

func GetIntEnv

func GetIntEnv(key string) int64

func GetIntEnvWithDefault

func GetIntEnvWithDefault(key string, defaultValue int) int

GetIntEnvWithDefault gets int environment variable with default value

func GetIntValue

func GetIntValue(db *gorm.DB, key string, defaultVal int) int

func GetValue

func GetValue(db *gorm.DB, key string) string

func InitGlobalCache

func InitGlobalCache(maxSize int, expiration time.Duration)

func LoadAutoloads

func LoadAutoloads(db *gorm.DB)

func LoadEnv

func LoadEnv(env string) error

LoadEnv Load .env file based on environment

func LoadEnvs

func LoadEnvs(objPtr any)

load envs to struct

func LookupEnv

func LookupEnv(key string) (value string, found bool)

func SetValue

func SetValue(db *gorm.DB, key, value, format string, autoload, public bool)

Types

type Config

type Config struct {
	ID        uint   `json:"id" gorm:"primaryKey"`
	Key       string `json:"key" gorm:"size:128;uniqueIndex"`
	Desc      string `json:"desc" gorm:"size:200"`
	Autoload  bool   `json:"autoload" gorm:"index"`
	Public    bool   `json:"public" gorm:"index" default:"false"`
	Format    string `json:"format" gorm:"size:20" default:"text" comment:"json,yaml,int,float,bool,text"`
	Value     string
	CreatedAt time.Time `json:"-" gorm:"autoCreateTime"`
	UpdatedAt time.Time `json:"-" gorm:"autoUpdateTime"`
}

func LoadPublicConfigs

func LoadPublicConfigs(db *gorm.DB) []Config

type ExpiredLRUCache

type ExpiredLRUCache[K comparable, V any] struct {
	*lru.Cache[K, expiredLRUCacheValue[V]]
	// contains filtered or unexported fields
}
var GlobalCache *ExpiredLRUCache[string, any]

GlobalCache is a global cache instance that supports generic key-value pairs

func NewExpiredLRUCache

func NewExpiredLRUCache[K comparable, V any](size int, expired time.Duration) *ExpiredLRUCache[K, V]

func (*ExpiredLRUCache[K, V]) Add

func (c *ExpiredLRUCache[K, V]) Add(key K, value V) (evicted bool)

func (*ExpiredLRUCache[K, V]) Contains

func (c *ExpiredLRUCache[K, V]) Contains(key K) bool

func (*ExpiredLRUCache[K, V]) Get

func (c *ExpiredLRUCache[K, V]) Get(key K) (value V, ok bool)

func (*ExpiredLRUCache[K, V]) Remove

func (c *ExpiredLRUCache[K, V]) Remove(key K) (present bool)

type SigHandler

type SigHandler struct {
	ID      uint
	Handler SignalHandler
}

type SigHandlerEvent

type SigHandlerEvent struct {
	EvType     int
	SignalName string
	SigHandler SigHandler
}

type SignalHandler

type SignalHandler func(sender any, params ...any)

Signals

type Signals

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

func NewSignals

func NewSignals() *Signals

func NewSignalsWithOptions

func NewSignalsWithOptions(opt SignalsOptions) *Signals

func Sig

func Sig() *Signals

func (*Signals) Clear

func (s *Signals) Clear(events ...string)

func (*Signals) Connect

func (s *Signals) Connect(event string, handler SignalHandler) uint

func (*Signals) DisableAsync

func (s *Signals) DisableAsync(ctx context.Context) error

func (*Signals) Disconnect

func (s *Signals) Disconnect(event string, id uint)

func (*Signals) Emit

func (s *Signals) Emit(event string, sender any, params ...any)

func (*Signals) EnableAsync

func (s *Signals) EnableAsync(workers, queueSize int, dropOnFull bool) error

func (*Signals) SetLogger

func (s *Signals) SetLogger(lg *zap.Logger)

func (*Signals) Shutdown

func (s *Signals) Shutdown(ctx context.Context) error

func (*Signals) Start

func (s *Signals) Start() error

func (*Signals) String

func (s *Signals) String() string

type SignalsOptions

type SignalsOptions struct {
	Logger     *zap.Logger
	Async      bool
	Workers    int
	QueueSize  int
	DropOnFull bool
}

type Snowflake

type Snowflake struct {
	// contains filtered or unexported fields
}
var SnowflakeUtil *Snowflake

func NewSnowflake

func NewSnowflake() (*Snowflake, error)

func (*Snowflake) GenID

func (sf *Snowflake) GenID() string

GenID 字符串格式(正数)

func (*Snowflake) NextID

func (sf *Snowflake) NextID() int64

NextID 生成 唯一 正数 int64

Jump to

Keyboard shortcuts

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