1
0
Fork 0

changes to go func

refactor/models
Matthew 2020-07-07 21:15:10 -04:00
parent 3a0305b6ec
commit 98ec12266d
No known key found for this signature in database
GPG Key ID: 210AF32ADE3B5C4B
2 changed files with 11 additions and 7 deletions

View File

@ -18,7 +18,7 @@ check_cert_signatures:
file dist/bin/checkCertSignatures
storage:
HOME=/root go build -ldflags="-s -w" -o dist/bin/storage ${storage_files}
HOME=/root go build -ldflags="-s -w" -buildmode=pie -o dist/bin/storage ${storage_files}
@chmod 740 dist/bin/storage
file dist/bin/storage

View File

@ -8,6 +8,7 @@ import (
"os"
"strings"
"time"
"sync"
"github.com/go-redis/redis/v7"
"go.mongodb.org/mongo-driver/bson"
@ -82,27 +83,30 @@ func handler(config ConfigStruct) {
cur, err := collection.Find(context.TODO(), bson.D{})
HandleError(err, 0)
var wg sync.WaitGroup
for cur.Next(context.TODO()) {
checkAccountSizeAndUpdate(cur.Current.Lookup("username").String(), cur.Current.Lookup("id").String())
wg.Add(1)
go checkAccountSizeAndUpdate(cur.Current.Lookup("username").String(), cur.Current.Lookup("id").String(), &wg)
fmt.Printf("Checking account information for %s\n", cur.Current.Lookup("username").String())
time.Sleep(300000 * time.Millisecond)
}
wg.Wait()
err = mongoClient.Disconnect(ctx)
HandleError(err, 1)
fmt.Println("CSD-GO-STR finished, exiting with code 0. [GO]")
os.Exit(0)
}
func checkAccountSizeAndUpdate(username string, id string) {
func checkAccountSizeAndUpdate(username string, id string, wg *sync.WaitGroup) {
var size float64 = 0
var userHomeDirectory string = strings.Replace(strings.Join([]string{"/home/", string(username)}, ""), "\"", "", -1)
usernameFormat := strings.Replace(username, "\"", "", -1)
sizeHome := DirSize(&userHomeDirectory)
size += sizeHome
status := RedisClient.Set("storage"+"-"+usernameFormat, size, 0)
fmt.Println(status.Name())
fmt.Printf("Redis Status: %s [GO]\n", status.Name())
if status.Err() != nil {
fmt.Println(status.Err())
}
fmt.Printf("Set Call | Username: %v, ID: %v | Bytes: %f\n [GO]", string(username), string(id), size)
fmt.Printf("Set Call | Username: %v, ID: %v | Bytes: %f [GO]\n", string(username), string(id), size)
wg.Done()
}