50 lines
1.1 KiB
Go
50 lines
1.1 KiB
Go
|
|
package main
|
||
|
|
|
||
|
|
import (
|
||
|
|
"time"
|
||
|
|
|
||
|
|
fwconfig "github.com/yourorg/go-dw-platform/framework/config"
|
||
|
|
)
|
||
|
|
|
||
|
|
type Config struct {
|
||
|
|
Port string
|
||
|
|
DB DBConfig
|
||
|
|
Batch BatchConfig
|
||
|
|
LogLevel string
|
||
|
|
}
|
||
|
|
|
||
|
|
type DBConfig struct {
|
||
|
|
DSN string
|
||
|
|
MaxConns int32
|
||
|
|
MinConns int32
|
||
|
|
MaxConnLifetime time.Duration
|
||
|
|
MaxConnIdleTime time.Duration
|
||
|
|
}
|
||
|
|
|
||
|
|
type BatchConfig struct {
|
||
|
|
Size int
|
||
|
|
TimeoutSec int
|
||
|
|
MaxRetries int
|
||
|
|
RetryDelay time.Duration
|
||
|
|
}
|
||
|
|
|
||
|
|
func LoadConfig() *Config {
|
||
|
|
return &Config{
|
||
|
|
Port: fwconfig.GetString("PORT", "8080"),
|
||
|
|
DB: DBConfig{
|
||
|
|
DSN: fwconfig.GetString("DATABASE_DSN", ""),
|
||
|
|
MaxConns: int32(fwconfig.GetInt("DB_MAX_CONNS", 25)),
|
||
|
|
MinConns: int32(fwconfig.GetInt("DB_MIN_CONNS", 5)),
|
||
|
|
MaxConnLifetime: 15 * time.Minute,
|
||
|
|
MaxConnIdleTime: 5 * time.Minute,
|
||
|
|
},
|
||
|
|
Batch: BatchConfig{
|
||
|
|
Size: fwconfig.GetInt("BATCH_SIZE", 5000),
|
||
|
|
TimeoutSec: fwconfig.GetInt("BATCH_TIMEOUT_SEC", 30),
|
||
|
|
MaxRetries: fwconfig.GetInt("BATCH_MAX_RETRIES", 3),
|
||
|
|
RetryDelay: time.Second,
|
||
|
|
},
|
||
|
|
LogLevel: fwconfig.GetString("LOG_LEVEL", "info"),
|
||
|
|
}
|
||
|
|
}
|