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.
51 lines
793 B
Go
51 lines
793 B
Go
2 years ago
|
package configs
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"os"
|
||
|
"sync"
|
||
|
)
|
||
|
|
||
|
type AppConfig struct {
|
||
|
Name string
|
||
|
Env string
|
||
|
}
|
||
|
|
||
|
type DbConfig struct {
|
||
|
Host string
|
||
|
Port string
|
||
|
Dbname string
|
||
|
Username string
|
||
|
Password string
|
||
|
}
|
||
|
|
||
|
type Configs struct {
|
||
|
Appconfig AppConfig
|
||
|
Dbconfig DbConfig
|
||
|
}
|
||
|
|
||
|
var lock = &sync.Mutex{}
|
||
|
var configs *Configs
|
||
|
|
||
|
func GetInstance() *Configs {
|
||
|
fmt.Println("configs", configs)
|
||
|
if configs == nil {
|
||
|
lock.Lock()
|
||
|
configs = &Configs{
|
||
|
Appconfig: AppConfig{
|
||
|
Name: os.Getenv("APP_NAME"),
|
||
|
Env: os.Getenv("APP_ENV"),
|
||
|
},
|
||
|
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"),
|
||
|
},
|
||
|
}
|
||
|
lock.Unlock()
|
||
|
}
|
||
|
return configs
|
||
|
}
|