-
Notifications
You must be signed in to change notification settings - Fork 0
/
nextcloud.go
150 lines (129 loc) · 4.21 KB
/
nextcloud.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package main
import (
"encoding/json"
"fmt"
"strconv"
)
const (
nextCloudYes = `"yes"`
nextCloudNo = `"no"`
)
type NextCloudRoot struct {
Ocs NextCloudOcs `json:"ocs"`
}
type NextCloudOcs struct {
Data NextCloudData `json:"data"`
Meta NextCloudMeta `json:"meta"`
}
type NextCloudData struct {
ActiveUsers NextCloudActiveUsers `json:"activeUsers"`
Nextcloud NextcloudStruct `json:"nextcloud"`
Server NextCloudServer `json:"server"`
}
type NextCloudActiveUsers struct {
Last1Day int `json:"last24hours"`
Last24Hour int `json:"last1hour"`
Last5Minutes int `json:"last5minutes"`
}
type NextCloudMeta struct {
Message string `json:"message"`
Status string `json:"status"`
StatusCode int `json:"statuscode"`
}
type NextcloudStruct struct {
Shares NextCloudShares `json:"shares"`
Storage NextCloudStorage `json:"storage"`
System NextCloudSystem `json:"system"`
}
type NextCloudServer struct {
Database NextCloudDatabase `json:"database"`
PHP NextCloudPHP `json:"php"`
Webserver string `json:"webserver"`
}
type NextCloudShares struct {
NumFedSharesReceived int `json:"num_fed_shares_received"`
NumFedSharesSent int `json:"num_fed_shares_sent"`
NumShares int `json:"num_shares"`
NumSharesGroups int `json:"num_shares_groups"`
NumSharesLink int `json:"num_shares_link"`
NumSharesLinkNoPassword int `json:"num_shares_link_no_password"`
NumSharesMail int `json:"num_shares_mail"`
NumSharesRoom int `json:"num_shares_room"`
NumSharesUser int `json:"num_shares_user"`
}
type NextCloudStorage struct {
NumUsers int `json:"num_users"`
NumFiles int `json:"num_files"`
NumStorages int `json:"num_storages"`
NumStoragesLocal int `json:"num_storages_local"`
NumStoragesHome int `json:"num_storages_home"`
NumStoragesOther int `json:"num_storages_other"`
}
type NextCloudSystem struct {
Apps *NextCloudApps `json:"apps"`
CPULoad []float64 `json:"cpuload"`
Debug NextCloudYesNo `json:"debug"`
EnableAvatars NextCloudYesNo `json:"enable_avatars"`
EnablePreviews NextCloudYesNo `json:"enable_previews"`
FilelockingEnabled NextCloudYesNo `json:"filelocking.enabled"`
FreeSpace int64 `json:"freespace"`
MemFree int64 `json:"mem_free"`
MemTotal int64 `json:"mem_total"`
MemcacheDistributed string `json:"memcache.distributed"`
MemcacheLocal string `json:"memcache.local"`
MemcacheLocking string `json:"memcache.locking"`
SwapFree int64 `json:"swap_free"`
SwapTotal int64 `json:"swap_total"`
Theme string `json:"theme"`
Update *NextcloudUpdate `json:"update"`
Version string `json:"version"`
}
type NextCloudDatabase struct {
Size NextCloudIntOrString `json:"size"`
Type string `json:"type"`
Version string `json:"version"`
}
type NextCloudPHP struct {
MaxExecutionTime int `json:"max_execution_time"`
MemoryLimit int64 `json:"memory_limit"`
UploadMaxFileSize int64 `json:"upload_max_filesize"`
Version string `json:"version"`
}
type NextCloudApps struct {
//AppUpdates map[string]string `json:"app_updates"`
NumInstalled int `json:"num_installed"`
NumUpdatesAvailable int `json:"num_updates_available"`
}
type NextcloudUpdate struct {
Available bool `json:"available"`
LastUpdateDate int64 `json:"lastupdatedat"`
}
type NextCloudYesNo bool
func (n *NextCloudYesNo) UnmarshalJSON(data []byte) error {
var err error
switch string(data) {
case nextCloudYes:
*n = true
case nextCloudNo:
*n = false
default:
err = fmt.Errorf("cannot unmarshal: %v", data)
}
return err
}
type NextCloudIntOrString int64
func (n *NextCloudIntOrString) UnmarshalJSON(data []byte) error {
if data[0] != '"' {
return json.Unmarshal(data, (*int64)(n))
}
var s string
if err := json.Unmarshal(data, &s); err != nil {
return err
}
i, err := strconv.ParseInt(s, 10, 64)
if err != nil {
return err
}
*n = NextCloudIntOrString(i)
return nil
}