1
0
Fork 0

fixes for disk calculation issues

refactor/models
Matthew 2020-06-28 22:21:42 -04:00
parent 81b19b6267
commit 2991ffb455
No known key found for this signature in database
GPG Key ID: 210AF32ADE3B5C4B
1 changed files with 10 additions and 13 deletions

View File

@ -13,17 +13,14 @@ import (
"time" "time"
) )
// RedisClient the Redis client
var RedisClient *redis.Client
// ConfigStruct the configuration struct // ConfigStruct the configuration struct
type ConfigStruct struct { type ConfigStruct struct {
MongoDB string `json:"mongoURL"` MongoDB string `json:"mongoURL"`
} }
// Config config
var Config *ConfigStruct
// RedisClient the Redis client
var RedisClient *redis.Client
// Account represents an user's account. // Account represents an user's account.
type Account struct { type Account struct {
Username string `json:"username"` Username string `json:"username"`
@ -45,10 +42,10 @@ func HandleError(e error, serv int) {
func main() { func main() {
var status bool var status bool
Config := &ConfigStruct{} config := &ConfigStruct{}
file, err := ioutil.ReadFile("../config.json") file, err := ioutil.ReadFile("../config.json")
HandleError(err, 1) HandleError(err, 1)
err = json.Unmarshal(file, &Config) err = json.Unmarshal(file, &config)
RedisClient = redis.NewClient(&redis.Options{ RedisClient = redis.NewClient(&redis.Options{
Addr: "localhost:6379", Addr: "localhost:6379",
@ -64,15 +61,15 @@ func main() {
for { for {
fmt.Printf("Calling handler func [GO]\n") fmt.Printf("Calling handler func [GO]\n")
if status == false { if status == false {
handler(&status) handler(&status, *config)
time.Sleep(1000000 * time.Millisecond) time.Sleep(1000000 * time.Millisecond)
} }
} }
} }
func handler(status* bool) { func handler(status *bool, config ConfigStruct) {
*status = true *status = true
mongoClient, err := mongo.NewClient(options.Client().ApplyURI(Config.MongoDB)) mongoClient, err := mongo.NewClient(options.Client().ApplyURI(config.MongoDB))
HandleError(err, 1) HandleError(err, 1)
ctx, _ := context.WithTimeout(context.Background(), 10*time.Second) ctx, _ := context.WithTimeout(context.Background(), 10*time.Second)
err = mongoClient.Connect(ctx) err = mongoClient.Connect(ctx)