package config import ( "eta/eta_mini_ht_api/common/contants" "sync" ) var ( once sync.Once dbConfig *DBConfig ) type DBOpts struct { Url string Driver string } type DBConfig struct { BaseConfig opts DBOpts } func (r *DBConfig) GetUrl() string { return r.opts.Url } func (r *DBConfig) GetDriver() string { return r.opts.Driver } func (r *DBConfig) InitConfig() { opts := DBOpts{ Url: r.GetString("url"), Driver: r.GetString("driver"), } r.opts = opts } func NewDBConfig() Config { if dbConfig == nil { once.Do(func() { dbConfig = &DBConfig{ BaseConfig: BaseConfig{prefix: contants.DATABASE}, opts: DBOpts{}, } }) } return dbConfig } func init() { Register(contants.DATABASE, NewDBConfig) }