Documentation
¶
Index ¶
- Constants
- Variables
- func BytesToString(b []byte) string
- func CalculateFileHash(filePath string) (string, error)
- func ClampSnowflakeUint(id uint) uint
- func ConfigureConnectionPool(db *gorm.DB)
- func CopyFile(src, dst string) error
- func Difference[T comparable](slice1, slice2 []T) []T
- func EnsureDirectory(path string) error
- func EnvDuration(key string) (time.Duration, bool)
- func EnvFloat(key string) (float64, bool)
- func EnvInt(key string) (int, bool)
- func FileExists(path string) bool
- func GenerateID() string
- func GetBoolEnv(key string) bool
- func GetBoolOrDefault(key string, defaultValue bool) bool
- func GetContentType(suffix string) (tp string)
- func GetDistance(lon1, lat1, lon2, lat2 float64) float64
- func GetEnv(key string) string
- func GetFileSize(filePath string) (int64, error)
- func GetFileType(buf []byte) (fileType string)
- func GetFileTypeBySuffix(suffix string) int32
- func GetFloatEnv(key string) float64
- func GetFloatEnvWithDefault(key string, defaultValue float64) float64
- func GetFloatOrDefault(key string, defaultValue float64) float64
- func GetIntEnv(key string) int64
- func GetIntEnvWithDefault(key string, defaultValue int) int
- func GetIntOrDefault(key string, defaultValue int) int
- func GetStringOrDefault(key, defaultValue string) string
- func InArray[T comparable](needle T, haystack []T) bool
- func InitDatabase(logWrite io.Writer, driver, dsn string) (*gorm.DB, error)
- func Intersect[T comparable](slice1, slice2 []T) []T
- func IsDirectory(path string) bool
- func IsFile(path string) bool
- func Join[T any](arg []T, str string) string
- func LoadEnv(env string) error
- func LoadEnvs(objPtr any)
- func LookupEnv(key string) (value string, found bool)
- func MakeMigrates(db *gorm.DB, insts []any) error
- func Merge[T any](slice1, slice2 []T) []T
- func NewSnowflake() (*idgen.Snowflake, error)
- func NextSnowflakeUint() uint
- func ParseDuration(s string, defaultVal time.Duration) time.Duration
- func PositiveIntEnv(key string) (int, bool)
- func PurgeEnvCacheForTest()
- func RemoveDirectory(path string) error
- func RemoveFile(path string) error
- func RunInitSQL(db *gorm.DB, sqlFilePath string) error
- func StringToBytes(s string) []byte
- func Unique[T comparable](slice []T) []T
- type BaseModel
- type QueryResult
- type SigHandler
- type SignalHandler
- type Signals
Constants ¶
const ( FILE_TYPE_IMAGE int32 = 3 FILE_TYPE_FILE int32 = 4 FILE_TYPE_AUDIO int32 = 5 FILE_TYPE_MEDIA int32 = 6 )
Variables ¶
var SnowflakeUtil = (*idgen.Snowflake)(nil)
SnowflakeUtil is the package-level snowflake generator, initialised on load. Deprecated: use idgen.SnowflakeNext / idgen.SnowflakeNextUint directly.
Functions ¶
func BytesToString ¶ added in v0.2.0
BytesToString bytes to string Zero-copy
func CalculateFileHash ¶ added in v0.2.0
CalculateFileHash 计算文件的SHA1哈希
func ClampSnowflakeUint ¶
ClampSnowflakeUint clears the sign bit so IDs remain scannable from signed INTEGER columns. Deprecated: use idgen.ClampSnowflakeUint.
func ConfigureConnectionPool ¶
ConfigureConnectionPool configures the database connection pool. Overrides via env (positive ints only):
DB_MAX_OPEN_CONNS (default: postgres 40, others 200) DB_MAX_IDLE_CONNS (default: postgres 20, others 50) DB_CONN_MAX_LIFETIME (Go duration, default 1h) DB_CONN_MAX_IDLE_TIME (Go duration, default 30m)
func Difference ¶ added in v0.2.0
func Difference[T comparable](slice1, slice2 []T) []T
Difference get difference set slice1-intersection
func EnsureDirectory ¶ added in v0.2.0
EnsureDirectory 确保目录存在
func EnvDuration ¶
EnvDuration reads a Go duration env var (e.g. "30m", "1h"). Returns (0, false) when unset/invalid.
func EnvFloat ¶
EnvFloat reads a float environment variable. Returns (0, false) when unset or invalid.
func EnvInt ¶
EnvInt reads an integer environment variable. Returns (0, false) when unset or invalid.
func GetBoolEnv ¶
func GetBoolOrDefault ¶
GetBoolOrDefault gets boolean environment variable value, returns default if empty.
func GetContentType ¶ added in v0.2.0
func GetDistance ¶ added in v0.2.0
Calculate distance between two points
func GetFileSize ¶ added in v0.2.0
GetFileSize 获取文件大小
func GetFileType ¶ added in v0.2.0
func GetFileTypeBySuffix ¶ added in v0.2.0
func GetFloatEnv ¶
func GetFloatEnvWithDefault ¶
GetFloatEnvWithDefault gets float environment variable with default value
func GetFloatOrDefault ¶
GetFloatOrDefault gets float environment variable value, returns default if empty.
func GetIntEnvWithDefault ¶
GetIntEnvWithDefault gets int environment variable with default value
func GetIntOrDefault ¶
GetIntOrDefault gets integer environment variable value, returns default if zero.
func GetStringOrDefault ¶
GetStringOrDefault gets environment variable value, returns default if empty.
func InArray ¶ added in v0.2.0
func InArray[T comparable](needle T, haystack []T) bool
InArray check if element is in array
func InitDatabase ¶
InitDatabase creates a GORM DB connection. If driver or dsn is empty, it falls back to environment variables DB_DRIVER / DSN.
func Intersect ¶ added in v0.2.0
func Intersect[T comparable](slice1, slice2 []T) []T
Intersect get intersection
func MakeMigrates ¶
MakeMigrates runs AutoMigrate for each instance.
func NewSnowflake ¶
NewSnowflake creates a snowflake generator using MACHINE_ID env var. Deprecated: use idgen.NewSnowflake.
func NextSnowflakeUint ¶
func NextSnowflakeUint() uint
NextSnowflakeUint returns a snowflake id safe for uint + signed INTEGER stores. Deprecated: use idgen.SnowflakeNextUint.
func ParseDuration ¶
ParseDuration parses duration string with default fallback.
func PositiveIntEnv ¶
PositiveIntEnv reads a strictly positive integer env var. Returns (0, false) when unset, invalid, or <= 0.
func PurgeEnvCacheForTest ¶
func PurgeEnvCacheForTest()
PurgeEnvCacheForTest clears cached environment lookups. Tests that mutate process env via t.Setenv should call this in t.Cleanup when other tests wire components that read digest secrets from env.
func RunInitSQL ¶ added in v0.3.0
RunInitSQL executes SQL statements from a local .sql file segment by segment (split by semicolon). Comment lines starting with -- or # and empty lines are skipped. Idempotent scripts should use IF NOT EXISTS in SQL for protection.
func StringToBytes ¶ added in v0.2.0
StringToBytes string to bytes Zero-copy
func Unique ¶ added in v0.2.0
func Unique[T comparable](slice []T) []T
Unique remove duplicates from array
Types ¶
type BaseModel ¶
type BaseModel struct {
ID uint `json:"id,string" gorm:"primaryKey;autoIncrement:false"`
CreatedAt time.Time `json:"createdAt" gorm:"autoCreateTime;comment:创建时间"`
UpdatedAt time.Time `json:"updatedAt,omitempty" gorm:"autoUpdateTime;comment:更新时间"`
DeletedAt gorm.DeletedAt `json:"-" gorm:"index"`
CreateBy string `json:"createBy,omitempty" gorm:"size:128;comment:创建人"`
UpdateBy string `json:"updateBy,omitempty" gorm:"size:128;comment:更新人"`
Remark string `json:"remark,omitempty" gorm:"size:128;comment:备注"`
}
BaseModel is embedded by all GORM entities in this package.
func (*BaseModel) BeforeCreate ¶
BeforeCreate add snowflake id for base
func (*BaseModel) SetCreateInfo ¶
func (*BaseModel) SetUpdateInfo ¶
func (*BaseModel) SoftDelete ¶
type QueryResult ¶
QueryResult is the synchronous result collected by Signals.Query. Handlers fill in Value/Value2/Err during Emit; the caller reads them after all handlers have returned.
type SigHandler ¶
type SigHandler struct {
ID uint
Handler SignalHandler
}
SigHandler pairs a unique handler ID with its callback.
type SignalHandler ¶
SignalHandler is a callback invoked when a signal event is emitted. sender is the originator of the event; params are arbitrary event data.
type Signals ¶
type Signals struct {
// contains filtered or unexported fields
}
Signals is a process-wide synchronous event bus.
Concurrency contract:
- sigHandlers is copy-on-write. Connect/Disconnect never mutate a slice that a concurrent Emit may already be iterating; they publish a fresh slice instead. Emit can therefore snapshot under RLock and invoke handlers with the lock released.
- Releasing the lock before invoking handlers is what makes reentrancy safe: handlers routinely Connect/Disconnect (notably one-shot handlers that unsubscribe themselves) and would otherwise self-deadlock.
func (*Signals) Connect ¶
func (s *Signals) Connect(event string, handler SignalHandler) uint
Connect registers a handler for the given event and returns its handler ID. The handler will be invoked on subsequent Emit calls for this event.
func (*Signals) Disconnect ¶
Disconnect removes the handler with the given ID from the event.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
audioutil
module
|
|
|
authcontext
module
|
|
|
barcode
module
|
|
|
cache
module
|
|
|
redis
module
|
|
|
circuitbreaker
module
|
|
|
compress
module
|
|
|
config
module
|
|
|
constants
module
|
|
|
convert
module
|
|
|
cron
module
|
|
|
crypto
module
|
|
|
eventbus
module
|
|
|
geoip
module
|
|
|
hash
module
|
|
|
i18n
module
|
|
|
gin
module
|
|
|
mymemory
module
|
|
|
idgen
module
|
|
|
imageutil
module
|
|
|
jwtutil
module
|
|
|
gin
module
|
|
|
limiter
module
|
|
|
count
module
|
|
|
tokenbucket
module
|
|
|
lock
module
|
|
|
logger
module
|
|
|
gin
module
|
|
|
mathutil
module
|
|
|
metrics
module
|
|
|
middleware
module
|
|
|
migration
module
|
|
|
gormmigrator
module
|
|
|
mq
module
|
|
|
activemq
module
|
|
|
redisstream
module
|
|
|
netutil
module
|
|
|
nltime
module
|
|
|
notification
module
|
|
|
email
module
|
|
|
inbox
module
|
|
|
opentelemetry
module
|
|
|
parser
module
|
|
|
password
module
|
|
|
payment
module
|
|
|
creem
module
|
|
|
epay
module
|
|
|
stripe
module
|
|
|
waffo
module
|
|
|
waffopancake
module
|
|
|
pinyin
module
|
|
|
pool
module
|
|
|
qrcode
module
|
|
|
queue
module
|
|
|
memory
module
|
|
|
random
module
|
|
|
rbac
module
|
|
|
response
module
|
|
|
gin
module
|
|
|
retry
module
|
|
|
sanitize
module
|
|
|
scheduler
module
|
|
|
search
module
|
|
|
bleve
module
|
|
|
stats
module
|
|
|
file
module
|
|
|
gin
module
|
|
|
memory
module
|
|
|
redis
module
|
|
|
stores
module
|
|
|
obs
module
|
|
|
system
module
|
|
|
timeutil
module
|
|
|
tracing
module
|
|
|
validate
module
|
|
|
videoutil
module
|