update dep

This commit is contained in:
Jon Lundy
2018-06-25 17:23:13 -06:00
parent 4e31982296
commit 229dd7620e
3 changed files with 58 additions and 59 deletions

View File

@@ -2,8 +2,6 @@ package main
import (
"bytes"
"fmt"
"github.com/docopt/docopt.go"
"github.com/spf13/viper"
"sour.is/x/toolbox/httpsrv"
@@ -55,6 +53,16 @@ var args map[string]interface{}
func init() {
var err error
viper.Set("app.name", AppName)
viper.SetDefault("app.version", "VERSION")
if AppVersion != "" {
viper.Set("app.version", AppVersion)
}
viper.SetDefault("app.build", "SNAPSHOT")
if AppBuild != "" {
viper.Set("app.build", AppBuild)
}
if args, err = docopt.Parse(AppUsage, nil, true, AppVersion, false); err != nil {
log.Fatal(err)
}
@@ -68,52 +76,36 @@ func init() {
log.Debug("Debug Logging.")
}
viper.SetConfigName("config")
if args["--config"] != nil {
viper.AddConfigPath(args["--config"].(string))
}
viper.AddConfigPath("/etc/opt/sour.is/paste/")
viper.AddConfigPath(".")
viper.SetConfigType("toml")
viper.ReadConfig(bytes.NewBuffer([]byte(defaultConfig)))
err = viper.MergeInConfig()
if err != nil { // Handle errors reading the config file
log.Fatalf("Fatal error config file: %s \n", err)
}
viper.Set("app.name", AppName)
viper.SetDefault("app.version", "VERSION")
if AppVersion != "" {
viper.Set("app.version", AppVersion)
}
viper.SetDefault("app.build", "SNAPSHOT")
if AppBuild != "" {
viper.Set("app.build", AppBuild)
}
log.Printf("%s (%s %s)\n",
viper.GetString("app.name"),
viper.GetString("app.version"),
viper.GetString("app.build"))
if args["serve"] == true {
viper.SetConfigName("config")
if args["--config"] != nil {
viper.AddConfigPath(args["--config"].(string))
}
viper.AddConfigPath("/etc/opt/sour.is/paste/")
viper.AddConfigPath(".")
viper.SetConfigType("toml")
viper.ReadConfig(bytes.NewBuffer([]byte(defaultConfig)))
err = viper.MergeInConfig()
if err != nil { // Handle errors reading the config file
log.Warningf("config file not found: %s \n", err)
} else {
log.Notice("Read config from: ", viper.ConfigFileUsed())
}
if args["--listen"] != nil {
viper.Set("http.listen", args["--listen"].(string))
}
log.Noticef("Startup: %s (%s %s)",
viper.GetString("app.name"),
viper.GetString("app.version"),
viper.GetString("app.build"))
log.Notice("Read config from: ", viper.ConfigFileUsed())
httpsrv.Config()
} else if args["version"] == true {
fmt.Printf("Version: %s (%s %s)\n",
viper.GetString("app.name"),
viper.GetString("app.version"),
viper.GetString("app.build"))
}
}

View File

@@ -30,11 +30,24 @@ import (
_ "sour.is/x/paste/src/docs"
_ "sour.is/x/paste/src/routes"
"sour.is/x/toolbox/httpsrv"
"os"
"os/signal"
"syscall"
"sour.is/x/toolbox/log"
)
func main() {
if args["serve"] == true {
httpsrv.Run()
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
s := <-c
log.Debugf("Got Signal %d", s)
httpsrv.Shutdown()
log.Debug("DONE")
}
}