A comprehensive Go utility library containing various tools and helpers for building robust applications.
go get trellis.tech/trellis/common.v3
config): JSON/YAML config with #include support and variable substitutionlogger): Logrus integration with file rotation (time/size-based)crypto): Hash, encryption, JWT, TLS helpersorm/txorm, orm/transaction): XORM wrapper and transaction managementstorage/cache): LRU cache with expiration and table managementstorage/pool): Generic connection pool with health checksstorage/data-structures): Stack, queue, MPSC lock-free queuemiddleware/ratelimit): Token bucket with Redis supportmiddleware/circuitbreaker): Three-state circuit breakermiddleware/tracing): Trace ID generation and propagationid/uuid): UUID generation and validationerrors/errcode): Structured error codes and aggregationstate-machine/fsm): Finite state machine with YAML configid): Snowflake ID generator, UUID generation and validationevent-plugin): Event bus, dependency injection, plugin systemimport "trellis.tech/trellis/common.v3/config"
cfg, err := config.NewConfig("config.yaml")
appName := cfg.GetString("app.name")
Include support: Use #include in YAML config files (must be quoted: "#include": "other.yaml")
import "trellis.tech/trellis/common.v3/logger"
config := logger.DefaultRotateLogsConfig("/var/log/app.log")
config.RotateMode = logger.RotateModeDay
config.MaxSize = 100 * 1024 * 1024
logrusLogger, _ := logger.NewLogrusLoggerWithRotate(config)
import (
"trellis.tech/trellis/common.v3/utils/slice"
"trellis.tech/trellis/common.v3/id/uuid"
"trellis.tech/trellis/common.v3/utils/retry"
)
// Slice operations
evens := slice.Filter([]int{1,2,3,4,5}, func(x int) bool { return x%2 == 0 })
sum := slice.Reduce(numbers, 0, func(acc, x int) int { return acc + x })
// UUID generation
id := uuid.New()
// Retry mechanism
err := retry.Do(ctx, retry.Config{MaxRetries: 3}, func() error {
return someOperation()
})
make unittest # Run all tests
make gofmt # Format code
make build # Build all packages