slowlorisdb/config/conifg.go
config/conifg.goRaw
1package config
2
3import (
4 "strings"
5
6 "github.com/spf13/viper"
7 "github.com/urfave/cli"
8)
9
10type Config struct {
11 Port string
12 Dest string
13}
14
15var C Config
16
17func MustRead(c *cli.Context) error {
18 viper.SetConfigType("yaml")
19 viper.SetConfigName("config")
20 viper.AddConfigPath(".") // adding home directory as first search path
21 viper.SetEnvPrefix("slowlorisdb") // so viper.AutomaticEnv will get matching envvars starting with O2M_
22 viper.AutomaticEnv() // read in environment variables that match
23 viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
24
25 if c.GlobalString("config") != "" {
26 viper.SetConfigFile(c.GlobalString("config"))
27 }
28
29 if err := viper.ReadInConfig(); err != nil {
30 return err
31 }
32 if err := viper.Unmarshal(&C); err != nil {
33 return err
34 }
35 return nil
36}