You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.2 KiB
Go

2 years ago
package configs
import (
"os"
"sync"
)
type AppConfig struct {
Name string
Env string
Port string
2 years ago
}
type DbConfig struct {
Host string
Port string
Dbname string
Username string
Password string
DbIsMigrate bool
2 years ago
}
type RedisConfig struct {
Host string
Port string
Password string
}
2 years ago
type Configs struct {
Appconfig AppConfig
Dbconfig DbConfig
Redisconfig RedisConfig
2 years ago
}
var lock = &sync.Mutex{}
var configs *Configs
func GetInstance() *Configs {
if configs == nil {
lock.Lock()
configs = &Configs{
Appconfig: AppConfig{
Name: os.Getenv("APP_NAME"),
Env: os.Getenv("APP_ENV"),
Port: os.Getenv("APP_PORT"),
2 years ago
},
Dbconfig: DbConfig{
Host: os.Getenv("DB_HOST"),
Port: os.Getenv("DB_PORT"),
Dbname: os.Getenv("DB_NAME"),
Username: os.Getenv("DB_USER"),
Password: os.Getenv("DB_PASS"),
DbIsMigrate: os.Getenv("DB_ISMIGRATE") == "true",
2 years ago
},
Redisconfig: RedisConfig{
Host: os.Getenv("REDIS_HOST"),
Port: os.Getenv("REDIS_PORT"),
Password: os.Getenv("REDIS_PASSWORD"),
},
2 years ago
}
lock.Unlock()
}
// fmt.Println("[CONFIG] : ", &configs)
2 years ago
return configs
}