initial simple peer, add config reader

This commit is contained in:
arnaucube
2019-04-13 03:23:12 +02:00
parent 0a48c937b2
commit ff73690719
5 changed files with 444 additions and 0 deletions

36
config/conifg.go Normal file
View File

@@ -0,0 +1,36 @@
package config
import (
"strings"
"github.com/spf13/viper"
"github.com/urfave/cli"
)
type Config struct {
Port string
Dest string
}
var C Config
func MustRead(c *cli.Context) error {
viper.SetConfigType("yaml")
viper.SetConfigName("config")
viper.AddConfigPath(".") // adding home directory as first search path
viper.SetEnvPrefix("slowlorisdb") // so viper.AutomaticEnv will get matching envvars starting with O2M_
viper.AutomaticEnv() // read in environment variables that match
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
if c.GlobalString("config") != "" {
viper.SetConfigFile(c.GlobalString("config"))
}
if err := viper.ReadInConfig(); err != nil {
return err
}
if err := viper.Unmarshal(&C); err != nil {
return err
}
return nil
}