now uses viper for configuration

This commit is contained in:
Jeffrey Paul 2018-11-03 08:32:24 -07:00
parent 8ff07a4a0b
commit 3d6bf1e08f
Signed by: sneak
GPG Key ID: 052443F4DF2A55C2
2 changed files with 30 additions and 13 deletions

4
app.go
View File

@ -41,8 +41,8 @@ func (self *App) main() {
func (self *App) mainloop() { func (self *App) mainloop() {
log.Infof("using %d fetching threads", self.config.desiredFetcherThreads) log.Infof("using %d fetching threads", self.config.desiredFetcherThreads)
//batchSize := uint(1000) batchSize := uint(1000)
batchSize := uint(10) //batchSize := uint(10)
var start BlockNumber var start BlockNumber
var end BlockNumber var end BlockNumber
for { for {

39
main.go
View File

@ -1,21 +1,38 @@
package main package main
//import "github.com/spf13/viper" import "github.com/spf13/viper"
//import "encoding/json"
import log "github.com/sirupsen/logrus" import log "github.com/sirupsen/logrus"
const steemAPIURL = "https://api.steemit.com" // STEEM_APIURL=https://api.steem.house ./steem-block-db
const redisUrl = "localhost:6379"
//const steemAPIURL = "http://10.100.202.175:8090"
//const steemAPIURL = "http://las2.local:8090"
func main() { 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{ app := NewApp(&appconfig{
logLevel: log.DebugLevel, logLevel: logLevel,
// logLevel: log.InfoLevel, apiUrl: apiurl,
apiUrl: steemAPIURL, redisUrl: redis,
redisUrl: redisUrl,
desiredFetcherThreads: 40, desiredFetcherThreads: 40,
}) })
app.main() app.main()