/
config.go
57 lines (50 loc) · 1.41 KB
/
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package effx
import (
"fmt"
"github.com/urfave/cli/v2"
)
// Configuration encapsulates information needed for communicating with effx
type Configuration struct {
APIHost string
APIKey string
Disable cli.StringSlice
}
// Validate ensures the configuration provided contains the required information.
func (c *Configuration) Validate() error {
if c.APIHost == "" {
return fmt.Errorf("an api host must be provided")
} else if c.APIKey == "" {
return fmt.Errorf("an api key must be provided")
}
return nil
}
// DefaultConfigWithFlags returns configuration and flags specific to effx
func DefaultConfigWithFlags() (*Configuration, []cli.Flag) {
cfg := &Configuration{
APIHost: "api.effx.io",
}
flags := []cli.Flag{
&cli.StringFlag{
Name: "effx-api-host",
Usage: "where the effx api is located",
Destination: &(cfg.APIHost),
Value: cfg.APIHost,
EnvVars: []string{"EFFX_API_HOST"},
},
&cli.StringFlag{
Name: "effx-api-key",
Usage: "the key associated with your effx acount",
Destination: &(cfg.APIKey),
Value: cfg.APIKey,
EnvVars: []string{"EFFX_API_KEY"},
},
&cli.StringSliceFlag{
Name: "disable",
Usage: "a comma seperated list of features to disable, for example language detection",
Destination: &cfg.Disable,
Value: &cli.StringSlice{},
EnvVars: []string{"DISABLE"},
},
}
return cfg, flags
}