Simplify project documentation and release notes
This commit is contained in:
@@ -7,19 +7,14 @@ import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
mysqlDriver "github.com/go-sql-driver/mysql"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Server ServerConfig `yaml:"server"`
|
||||
Database DatabaseConfig `yaml:"database"`
|
||||
Pricing PricingConfig `yaml:"pricing"`
|
||||
Export ExportConfig `yaml:"export"`
|
||||
Alerts AlertsConfig `yaml:"alerts"`
|
||||
Notifications NotificationsConfig `yaml:"notifications"`
|
||||
Logging LoggingConfig `yaml:"logging"`
|
||||
Backup BackupConfig `yaml:"backup"`
|
||||
Server ServerConfig `yaml:"server"`
|
||||
Export ExportConfig `yaml:"export"`
|
||||
Logging LoggingConfig `yaml:"logging"`
|
||||
Backup BackupConfig `yaml:"backup"`
|
||||
}
|
||||
|
||||
type ServerConfig struct {
|
||||
@@ -30,64 +25,6 @@ type ServerConfig struct {
|
||||
WriteTimeout time.Duration `yaml:"write_timeout"`
|
||||
}
|
||||
|
||||
type DatabaseConfig struct {
|
||||
Host string `yaml:"host"`
|
||||
Port int `yaml:"port"`
|
||||
Name string `yaml:"name"`
|
||||
User string `yaml:"user"`
|
||||
Password string `yaml:"password"`
|
||||
MaxOpenConns int `yaml:"max_open_conns"`
|
||||
MaxIdleConns int `yaml:"max_idle_conns"`
|
||||
ConnMaxLifetime time.Duration `yaml:"conn_max_lifetime"`
|
||||
}
|
||||
|
||||
func (d *DatabaseConfig) DSN() string {
|
||||
cfg := mysqlDriver.NewConfig()
|
||||
cfg.User = d.User
|
||||
cfg.Passwd = d.Password
|
||||
cfg.Net = "tcp"
|
||||
cfg.Addr = net.JoinHostPort(d.Host, strconv.Itoa(d.Port))
|
||||
cfg.DBName = d.Name
|
||||
cfg.ParseTime = true
|
||||
cfg.Loc = time.Local
|
||||
cfg.Params = map[string]string{
|
||||
"charset": "utf8mb4",
|
||||
}
|
||||
return cfg.FormatDSN()
|
||||
}
|
||||
|
||||
type PricingConfig struct {
|
||||
DefaultMethod string `yaml:"default_method"`
|
||||
DefaultPeriodDays int `yaml:"default_period_days"`
|
||||
FreshnessGreenDays int `yaml:"freshness_green_days"`
|
||||
FreshnessYellowDays int `yaml:"freshness_yellow_days"`
|
||||
FreshnessRedDays int `yaml:"freshness_red_days"`
|
||||
MinQuotesForMedian int `yaml:"min_quotes_for_median"`
|
||||
PopularityDecayDays int `yaml:"popularity_decay_days"`
|
||||
}
|
||||
|
||||
type ExportConfig struct {
|
||||
TempDir string `yaml:"temp_dir"`
|
||||
MaxFileAge time.Duration `yaml:"max_file_age"`
|
||||
CompanyName string `yaml:"company_name"`
|
||||
}
|
||||
|
||||
type AlertsConfig struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
CheckInterval time.Duration `yaml:"check_interval"`
|
||||
HighDemandThreshold int `yaml:"high_demand_threshold"`
|
||||
TrendingThresholdPercent int `yaml:"trending_threshold_percent"`
|
||||
}
|
||||
|
||||
type NotificationsConfig struct {
|
||||
EmailEnabled bool `yaml:"email_enabled"`
|
||||
SMTPHost string `yaml:"smtp_host"`
|
||||
SMTPPort int `yaml:"smtp_port"`
|
||||
SMTPUser string `yaml:"smtp_user"`
|
||||
SMTPPassword string `yaml:"smtp_password"`
|
||||
FromAddress string `yaml:"from_address"`
|
||||
}
|
||||
|
||||
type LoggingConfig struct {
|
||||
Level string `yaml:"level"`
|
||||
Format string `yaml:"format"`
|
||||
@@ -95,6 +32,10 @@ type LoggingConfig struct {
|
||||
FilePath string `yaml:"file_path"`
|
||||
}
|
||||
|
||||
// ExportConfig is kept for constructor compatibility in export services.
|
||||
// Runtime no longer persists an export section in config.yaml.
|
||||
type ExportConfig struct{}
|
||||
|
||||
type BackupConfig struct {
|
||||
Time string `yaml:"time"`
|
||||
}
|
||||
@@ -132,38 +73,6 @@ func (c *Config) setDefaults() {
|
||||
c.Server.WriteTimeout = 30 * time.Second
|
||||
}
|
||||
|
||||
if c.Database.Port == 0 {
|
||||
c.Database.Port = 3306
|
||||
}
|
||||
if c.Database.MaxOpenConns == 0 {
|
||||
c.Database.MaxOpenConns = 25
|
||||
}
|
||||
if c.Database.MaxIdleConns == 0 {
|
||||
c.Database.MaxIdleConns = 5
|
||||
}
|
||||
if c.Database.ConnMaxLifetime == 0 {
|
||||
c.Database.ConnMaxLifetime = 5 * time.Minute
|
||||
}
|
||||
|
||||
if c.Pricing.DefaultMethod == "" {
|
||||
c.Pricing.DefaultMethod = "weighted_median"
|
||||
}
|
||||
if c.Pricing.DefaultPeriodDays == 0 {
|
||||
c.Pricing.DefaultPeriodDays = 90
|
||||
}
|
||||
if c.Pricing.FreshnessGreenDays == 0 {
|
||||
c.Pricing.FreshnessGreenDays = 30
|
||||
}
|
||||
if c.Pricing.FreshnessYellowDays == 0 {
|
||||
c.Pricing.FreshnessYellowDays = 60
|
||||
}
|
||||
if c.Pricing.FreshnessRedDays == 0 {
|
||||
c.Pricing.FreshnessRedDays = 90
|
||||
}
|
||||
if c.Pricing.MinQuotesForMedian == 0 {
|
||||
c.Pricing.MinQuotesForMedian = 3
|
||||
}
|
||||
|
||||
if c.Logging.Level == "" {
|
||||
c.Logging.Level = "info"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user