Work better with no config
This commit is contained in:
parent
34e3d0ee1b
commit
8da4b60f28
18
main.go
18
main.go
@ -37,8 +37,7 @@ func main() {
|
|||||||
|
|
||||||
if err := viper.ReadInConfig(); err != nil {
|
if err := viper.ReadInConfig(); err != nil {
|
||||||
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
|
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
|
||||||
// no config file maybe that's ok
|
// don't worry be happy
|
||||||
panic(err)
|
|
||||||
} else {
|
} else {
|
||||||
// Config file was found but another error was produced
|
// Config file was found but another error was produced
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
@ -56,14 +55,7 @@ func main() {
|
|||||||
port := viper.GetInt("port") // retrieve value from viper
|
port := viper.GetInt("port") // retrieve value from viper
|
||||||
authtoken := viper.GetString("authtoken")
|
authtoken := viper.GetString("authtoken")
|
||||||
|
|
||||||
if authtoken == "" {
|
|
||||||
log.Fatal("authtoken must be set")
|
|
||||||
}
|
|
||||||
|
|
||||||
address := viper.GetString("address")
|
address := viper.GetString("address")
|
||||||
if !*isServer && address == "" {
|
|
||||||
log.Fatal("an address must be provided on the command line, or configuration")
|
|
||||||
}
|
|
||||||
|
|
||||||
flag.Usage = func() {
|
flag.Usage = func() {
|
||||||
fmt.Fprintf(flag.CommandLine.Output(), "Usage of %s:\n", os.Args[0])
|
fmt.Fprintf(flag.CommandLine.Output(), "Usage of %s:\n", os.Args[0])
|
||||||
@ -104,6 +96,14 @@ environment variable. This may be preferable in some environments.
|
|||||||
log.SetLevel(log.DebugLevel)
|
log.SetLevel(log.DebugLevel)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if authtoken == "" {
|
||||||
|
log.Fatal("authtoken must be set")
|
||||||
|
}
|
||||||
|
|
||||||
|
if !*isServer && address == "" {
|
||||||
|
log.Fatal("an address must be provided on the command line, or configuration")
|
||||||
|
}
|
||||||
|
|
||||||
if *isServer {
|
if *isServer {
|
||||||
s := Server{port: port, authToken: authtoken}
|
s := Server{port: port, authToken: authtoken}
|
||||||
s.Run()
|
s.Run()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user