-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
39 lines (31 loc) · 871 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
package mikku
import (
"errors"
"fmt"
"github.com/kelseyhightower/envconfig"
)
var (
errEmptyGitHubAccessToken = errors.New("should be set MIKKU_GITHUB_ACCESS_TOKEN")
errEmptyGitHubOwner = errors.New("should be set MIKKU_GITHUB_OWNER")
)
// Config represents config using all commands
type Config struct {
GitHubAccessToken string `envconfig:"MIKKU_GITHUB_ACCESS_TOKEN" required:"true"`
GitHubOwner string `envconfig:"MIKKU_GITHUB_OWNER" required:"true"`
}
func (cfg *Config) validate() error {
if cfg.GitHubAccessToken == "" {
return errEmptyGitHubAccessToken
}
if cfg.GitHubOwner == "" {
return errEmptyGitHubOwner
}
return nil
}
func readConfig() (*Config, error) {
cfg := &Config{}
if err := envconfig.Process("", cfg); err != nil {
return nil, fmt.Errorf("failed to read environment variables: %w", err)
}
return cfg, nil
}