set cfg to env
This commit is contained in:
20
main.go
20
main.go
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user