-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
40 lines (32 loc) · 1000 Bytes
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"context"
"github.com/joho/godotenv"
"github.com/pkg/errors"
"github.com/sethvargo/go-envconfig"
log "github.com/sirupsen/logrus"
"io/fs"
)
type Config struct {
CalendarId string `env:"CALENDAR_ID"`
TelegramToken string `env:"TELEGRAM_TOKEN"`
TelegramChatId int64 `env:"TELEGRAM_CHAT_ID"`
LastCheckedFile string `env:"LAST_CHECKED_FILE, default=last_checked.txt"`
GoogleServiceAccountFile string `env:"GOOGLE_SERVICE_ACCOUNT_FILE, default=google_service_account.json"`
}
func ReadConfigFromEnv(ctx context.Context) (Config, error) {
var cfg Config
if err := envconfig.Process(ctx, &cfg); err != nil {
return cfg, errors.Wrap(err, "error processing config")
}
return cfg, nil
}
func LoadDotEnv() error {
var pathErr *fs.PathError
if err := godotenv.Load(".env"); errors.As(err, &pathErr) {
log.Info("couldn't find .env file, skipping .env file load")
} else if err != nil {
return err
}
return nil
}