-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathstorage.go
41 lines (35 loc) · 935 Bytes
/
storage.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package elevengo
import (
"context"
"github.com/deadblue/elevengo/lowlevel/api"
)
// StorageInfo describes storage space usage.
type StorageInfo struct {
// Total size in bytes.
Size int64
// Human-readable total size.
FormatSize string
// Used size in bytes.
Used int64
// Human-readable used size.
FormatUsed string
// Available size in bytes.
Avail int64
// Human-readable remain size.
FormatAvail string
}
// StorageStat gets storage size information.
func (a *Agent) StorageStat(info *StorageInfo) (err error) {
spec := (&api.IndexInfoSpec{}).Init()
if err = a.llc.CallApi(spec, context.Background()); err != nil {
return
}
space := spec.Result.SpaceInfo
info.Size = int64(space.Total.Size)
info.Used = int64(space.Used.Size)
info.Avail = int64(space.Remain.Size)
info.FormatSize = space.Total.SizeFormat
info.FormatUsed = space.Used.SizeFormat
info.FormatAvail = space.Remain.SizeFormat
return
}