From 2991ffb4550bc69afd377d4552ef71436f20f0a0 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sun, 28 Jun 2020 22:21:42 -0400 Subject: [PATCH] fixes for disk calculation issues --- src/go/storage/storage.go | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/go/storage/storage.go b/src/go/storage/storage.go index eb60035..afd6abf 100644 --- a/src/go/storage/storage.go +++ b/src/go/storage/storage.go @@ -13,17 +13,14 @@ import ( "time" ) -// ConfigStruct the configuration struct -type ConfigStruct struct { - MongoDB string `json:"mongoURL"` -} - -// Config config -var Config *ConfigStruct - // RedisClient the Redis client var RedisClient *redis.Client + // ConfigStruct the configuration struct + type ConfigStruct struct { + MongoDB string `json:"mongoURL"` + } + // Account represents an user's account. type Account struct { Username string `json:"username"` @@ -45,10 +42,10 @@ func HandleError(e error, serv int) { func main() { var status bool - Config := &ConfigStruct{} + config := &ConfigStruct{} file, err := ioutil.ReadFile("../config.json") HandleError(err, 1) - err = json.Unmarshal(file, &Config) + err = json.Unmarshal(file, &config) RedisClient = redis.NewClient(&redis.Options{ Addr: "localhost:6379", @@ -64,15 +61,15 @@ func main() { for { fmt.Printf("Calling handler func [GO]\n") if status == false { - handler(&status) + handler(&status, *config) time.Sleep(1000000 * time.Millisecond) } } } -func handler(status* bool) { +func handler(status *bool, config ConfigStruct) { *status = true - mongoClient, err := mongo.NewClient(options.Client().ApplyURI(Config.MongoDB)) + mongoClient, err := mongo.NewClient(options.Client().ApplyURI(config.MongoDB)) HandleError(err, 1) ctx, _ := context.WithTimeout(context.Background(), 10*time.Second) err = mongoClient.Connect(ctx)