99 lines
1.7 KiB
Go
99 lines
1.7 KiB
Go
package domain
|
|
|
|
import (
|
|
"log"
|
|
"os"
|
|
|
|
"github.com/joho/godotenv"
|
|
)
|
|
|
|
type Config struct {
|
|
Git GitConfig
|
|
Cloud CloudConfig
|
|
Coda CodaConfig
|
|
DB DBConfig
|
|
Telegram TelegramConfig
|
|
Discord DiscordConfig
|
|
}
|
|
|
|
type GitConfig struct {
|
|
BaseUrl string
|
|
Token string
|
|
User string
|
|
}
|
|
|
|
type CloudConfig struct {
|
|
BaseUrl string
|
|
User string
|
|
Pass string
|
|
RootDir string
|
|
}
|
|
|
|
type CodaConfig struct {
|
|
Farm string
|
|
Develop string
|
|
}
|
|
|
|
type DBConfig struct {
|
|
Host string
|
|
Port string
|
|
Name string
|
|
User string
|
|
Pass string
|
|
SslMode string
|
|
}
|
|
|
|
type TelegramConfig struct {
|
|
Token string
|
|
}
|
|
|
|
type DiscordConfig struct {
|
|
Token string
|
|
}
|
|
|
|
type ApplicationConfig struct {
|
|
Key string
|
|
ID int
|
|
}
|
|
|
|
// InitConfig
|
|
// InitConfig function reads provided file and setup envirmental variables;
|
|
func InitConfig(envFilePath string) Config {
|
|
err := godotenv.Load(envFilePath)
|
|
if err != nil {
|
|
log.Fatal("Error while loading env file")
|
|
}
|
|
|
|
return Config{
|
|
Git: GitConfig{
|
|
BaseUrl: os.Getenv("GIT_BASE_URL"),
|
|
Token: os.Getenv("GIT_TOKEN"),
|
|
User: os.Getenv("GIT_USER"),
|
|
},
|
|
Cloud: CloudConfig{
|
|
BaseUrl: os.Getenv("CLOUD_BASE_URL"),
|
|
User: os.Getenv("CLOUD_USER"),
|
|
Pass: os.Getenv("CLOUD_PASS"),
|
|
RootDir: os.Getenv("ROOTDIR"),
|
|
},
|
|
Coda: CodaConfig{
|
|
Farm: os.Getenv("CODA_TOKEN1"),
|
|
Develop: os.Getenv("CODA_TOKEN2"),
|
|
},
|
|
DB: DBConfig{
|
|
Host: os.Getenv("DB_HOST"),
|
|
Port: os.Getenv("DB_PORT"),
|
|
Name: os.Getenv("DB_NAME"),
|
|
User: os.Getenv("DB_USER"),
|
|
Pass: os.Getenv("DB_PASS"),
|
|
SslMode: os.Getenv("SSLMODE"),
|
|
},
|
|
Telegram: TelegramConfig{
|
|
Token: os.Getenv("TG_API"),
|
|
},
|
|
Discord: DiscordConfig{
|
|
Token: os.Getenv("DISCORD_TOKEN"),
|
|
},
|
|
}
|
|
}
|