We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ab22926 commit d7d16fdCopy full SHA for d7d16fd
stat.go
@@ -0,0 +1,28 @@
1
+package main
2
+
3
+import (
4
+ "fmt"
5
+ "log"
6
+ "sync/atomic"
7
+)
8
9
+var upload_size int64
10
+var download_size int64
11
12
+func calcUnit(cnt int64) string {
13
+ if cnt < 1024 {
14
+ return fmt.Sprintf("%d B", cnt)
15
+ } else if cnt < 1024*1024 {
16
+ return fmt.Sprintf("%.2f KB", float32(cnt)/1024)
17
+ } else if cnt < 1024*1024*1024 {
18
+ return fmt.Sprintf("%.2f MB", float32(cnt)/(1024*1024))
19
+ } else {
20
+ return fmt.Sprintf("%.2f GB", float32(cnt)/(1024*1024*1024))
21
+ }
22
+}
23
24
+func StatUpdate(up int64, down int64) {
25
+ atomic.AddInt64(&upload_size, up)
26
+ atomic.AddInt64(&download_size, down)
27
+ log.SetPrefix(fmt.Sprintf("[UP:%s DOWN:%s] ", calcUnit(upload_size), calcUnit(download_size)))
28
0 commit comments