From 3d6bf1e08f82447655777d8b4c105ed3cf576d88 Mon Sep 17 00:00:00 2001 From: Jeffrey Paul Date: Sat, 3 Nov 2018 08:32:24 -0700 Subject: [PATCH] now uses viper for configuration --- app.go | 4 ++-- main.go | 39 ++++++++++++++++++++++++++++----------- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/app.go b/app.go index 371e4c7..70198d1 100644 --- a/app.go +++ b/app.go @@ -41,8 +41,8 @@ func (self *App) main() { func (self *App) mainloop() { log.Infof("using %d fetching threads", self.config.desiredFetcherThreads) - //batchSize := uint(1000) - batchSize := uint(10) + batchSize := uint(1000) + //batchSize := uint(10) var start BlockNumber var end BlockNumber for { diff --git a/main.go b/main.go index 7ee53df..f8d1024 100644 --- a/main.go +++ b/main.go @@ -1,21 +1,38 @@ package main -//import "github.com/spf13/viper" -//import "encoding/json" +import "github.com/spf13/viper" import log "github.com/sirupsen/logrus" -const steemAPIURL = "https://api.steemit.com" -const redisUrl = "localhost:6379" - -//const steemAPIURL = "http://10.100.202.175:8090" -//const steemAPIURL = "http://las2.local:8090" +// STEEM_APIURL=https://api.steem.house ./steem-block-db func main() { + viper.SetConfigName("steem") + viper.AddConfigPath("/etc/steem") + viper.AddConfigPath("$HOME/.config/steem") + viper.SetEnvPrefix("steem") + viper.BindEnv("debug") + viper.BindEnv("redis") + viper.BindEnv("apiurl") + err := viper.ReadInConfig() // Find and read the config file if exists + if err != nil { + log.Infof("error reading config file: %s \n", err) + } + logLevel := log.InfoLevel + if viper.GetBool("debug") == true { + logLevel = log.DebugLevel + } + redis := "localhost:6379" + if viper.Get("redis") != nil { + redis = viper.GetString("redis") + } + apiurl := "https://api.steemit.com" + if viper.Get("apiurl") != nil { + apiurl = viper.GetString("apiurl") + } app := NewApp(&appconfig{ - logLevel: log.DebugLevel, - // logLevel: log.InfoLevel, - apiUrl: steemAPIURL, - redisUrl: redisUrl, + logLevel: logLevel, + apiUrl: apiurl, + redisUrl: redis, desiredFetcherThreads: 40, }) app.main()