From 229dd7620ee5e6f08d89dffc652daa05277c440d Mon Sep 17 00:00:00 2001 From: Jon Lundy Date: Mon, 25 Jun 2018 17:23:13 -0600 Subject: [PATCH] update dep --- Gopkg.lock | 32 ++++++++------------ cmd/paste/config.go | 72 ++++++++++++++++++++------------------------- cmd/paste/main.go | 13 ++++++++ 3 files changed, 58 insertions(+), 59 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index bc013ee..cbaf4d8 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -28,14 +28,14 @@ [[projects]] name = "github.com/gorilla/context" packages = ["."] - revision = "1ea25387ff6f684839d82767c1733ff4d4d15d0a" - version = "v1.1" + revision = "08b5f424b9271eedf6f9f0ce86cb9396ed337a42" + version = "v1.1.1" [[projects]] name = "github.com/gorilla/mux" packages = ["."] - revision = "53c1911da2b537f792e7cafcb446b05ffe33b996" - version = "v1.6.1" + revision = "e3702bed27f0d39777b0b37b664b6280e8ef8fbf" + version = "v1.6.2" [[projects]] branch = "master" @@ -57,20 +57,20 @@ [[projects]] name = "github.com/magiconair/properties" packages = ["."] - revision = "c3beff4c2358b44d0493c7dda585e7db7ff28ae6" - version = "v1.7.6" + revision = "c2353362d570a7bfa228149c62842019201cfb71" + version = "v1.8.0" [[projects]] branch = "master" name = "github.com/mitchellh/mapstructure" packages = ["."] - revision = "00c29f56e2386353d58c599509e8dc3801b0d716" + revision = "bb74f1db0675b241733089d5a1faa5dd8b0ef57b" [[projects]] name = "github.com/pelletier/go-toml" packages = ["."] - revision = "acdc4509485b587f5e675510c4f2c63e90ff68a8" - version = "v1.1.0" + revision = "c01d1270ff3e442a8a57cddc1c92dc1138598194" + version = "v1.2.0" [[projects]] name = "github.com/spf13/afero" @@ -78,8 +78,8 @@ ".", "mem" ] - revision = "63644898a8da0bc22138abf860edaf5277b6102e" - version = "v1.1.0" + revision = "787d034dfe70e44075ccc060d346146ef53270ad" + version = "v1.1.1" [[projects]] name = "github.com/spf13/cast" @@ -105,17 +105,11 @@ revision = "b5e8006cbee93ec955a89ab31e0e3ce3204f3736" version = "v1.0.2" -[[projects]] - branch = "master" - name = "golang.org/x/net" - packages = ["context"] - revision = "5f9ae10d9af5b1c89ae6904293b14b064d4ada23" - [[projects]] branch = "master" name = "golang.org/x/sys" packages = ["unix"] - revision = "cbbc999da32df943dac6cd71eb3ee39e1d7838b9" + revision = "a200a19cb90b19de298170992778b1fda7217bd6" [[projects]] name = "golang.org/x/text" @@ -146,7 +140,7 @@ "stats", "uuid" ] - revision = "269d338a355c78bd998da6be806d99216b4f19a0" + revision = "9487992f8fbf29e66bef06b4fa787389832193a4" [solve-meta] analyzer-name = "dep" diff --git a/cmd/paste/config.go b/cmd/paste/config.go index b48cc42..4fbda61 100644 --- a/cmd/paste/config.go +++ b/cmd/paste/config.go @@ -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")) } } diff --git a/cmd/paste/main.go b/cmd/paste/main.go index 4de4659..e684f63 100644 --- a/cmd/paste/main.go +++ b/cmd/paste/main.go @@ -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") } }