set cfg to env

This commit is contained in:
Smile Rex
2025-01-24 15:08:41 +03:00
parent 8dd981f0f6
commit e690b65294
2 changed files with 16 additions and 14 deletions

20
main.go
View File

@@ -8,24 +8,16 @@ import (
"time"
tele "gopkg.in/telebot.v4"
"gopkg.in/yaml.v3"
)
func config() models.Config {
file, err := os.Open("cfg.yml")
if err != nil {
log.Fatal(err)
return models.Config{
Token: os.Getenv("BOT_TOKEN"),
HostName: os.Getenv("DB_HOST"),
DbName: os.Getenv("DB_NAME"),
UserName: os.Getenv("DB_USER"),
Password: os.Getenv("DB_PASS"),
}
defer file.Close()
// unmarshal the YAML data into a struct
var config models.Config
err = yaml.NewDecoder(file).Decode(&config)
if err != nil {
log.Fatal(err)
}
return config
}
func main() {