aboutsummaryrefslogtreecommitdiffstats
path: root/golang/cmd/fatcatd/root.go
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2018-05-09 23:30:30 -0700
committerBryan Newbold <bnewbold@robocracy.org>2018-05-09 23:30:30 -0700
commitc5f0e88700ee11be7343ff11bcddf3c9a2a28486 (patch)
treed2236b4d5daa27fe52e5763c134043e6e7a5608c /golang/cmd/fatcatd/root.go
parent6f8177979c1dac59902d435cd8d7def38f4ba4d1 (diff)
downloadfatcat-c5f0e88700ee11be7343ff11bcddf3c9a2a28486.tar.gz
fatcat-c5f0e88700ee11be7343ff11bcddf3c9a2a28486.zip
refactor commands (cobra)
Diffstat (limited to 'golang/cmd/fatcatd/root.go')
-rw-r--r--golang/cmd/fatcatd/root.go65
1 files changed, 65 insertions, 0 deletions
diff --git a/golang/cmd/fatcatd/root.go b/golang/cmd/fatcatd/root.go
new file mode 100644
index 00000000..8c1bc586
--- /dev/null
+++ b/golang/cmd/fatcatd/root.go
@@ -0,0 +1,65 @@
+
+package main
+
+import (
+ "os"
+ "fmt"
+
+ log "github.com/sirupsen/logrus"
+ //middleware "github.com/go-openapi/runtime/middleware"
+ "github.com/spf13/viper"
+ "github.com/spf13/cobra"
+ "github.com/getsentry/raven-go"
+)
+
+var cfgFile = "";
+
+var rootCmd = &cobra.Command{
+ Use: "fatcatd",
+ Short: "REST API Server",
+ Long: "A scalable, versioned, API-oriented catalog of bibliographic entities and file metadata",
+}
+
+func init() {
+ cobra.OnInitialize(initConfig)
+ rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is ./fatcatd.toml)")
+ rootCmd.PersistentFlags().BoolP("verbose", "v", false, "increase logging volume")
+
+ rootCmd.AddCommand(serveCmd)
+}
+
+func initConfig() {
+ viper.SetDefault("port", 9411)
+ viper.SetDefault("verbose", true)
+
+ viper.SetEnvPrefix("FATCAT")
+ viper.AutomaticEnv()
+
+
+ if cfgFile != "" {
+ // Use config file from the flag.
+ viper.SetConfigFile(cfgFile)
+ } else {
+ viper.SetConfigType("toml")
+ viper.AddConfigPath(".")
+ viper.SetConfigName("fatcatd")
+ }
+
+ err := viper.ReadInConfig()
+ if err != nil {
+ log.Fatalf("Error loading config: %s \n", err)
+ }
+
+ // not default of stderr
+ log.SetOutput(os.Stdout);
+
+ raven.SetDSN(viper.GetString("sentry_dsn"));
+
+}
+
+func Execute() {
+ if err := rootCmd.Execute(); err != nil {
+ fmt.Println(err)
+ os.Exit(1)
+ }
+}