This repository was archived by the owner on Oct 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcommon_interface.go
More file actions
105 lines (89 loc) · 2.26 KB
/
common_interface.go
File metadata and controls
105 lines (89 loc) · 2.26 KB
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
package libwimark
import (
"bytes"
"encoding/json"
"strconv"
)
type ModuleStatus struct {
Service Module `json:"service"`
Id string `json:"id"`
Version string `json:"version"`
Commit string `json:"commit"`
Build int `json:"build"`
State ServiceState `json:"state"`
Meta interface{} `json:"meta,omitempty"`
Statics map[string]Version `json:"statics,omitempty"`
}
type CpeStatusMeta struct {
Model string `json:"model"`
Statics map[string]Version `json:"statics"`
}
type TunManagerBroadcastMeta struct {
Hostname string `json:"hostname"`
HostUUID string `json:"host_uuid"`
HostInterfaces []LinkDescriptor `json:"active_out_interfaces"`
HostTunnels []CPETunnelDescription `json:"active_cpe_tunnels"`
}
func (ms *ModuleStatus) UnmarshalJSON(b []byte) error {
var doc map[string]json.RawMessage
if err := json.Unmarshal(b, &doc); err != nil {
return err
}
type MS ModuleStatus
var s MS
if err := json.Unmarshal(b, &s); err != nil {
return err
}
*ms = ModuleStatus(s)
var meta, has_meta = doc["meta"]
has_meta = has_meta && !bytes.Equal(meta, []byte("null"))
switch ms.Service {
case ModuleCPE:
var m CpeStatusMeta
if has_meta {
if err := json.Unmarshal(meta, &m); err != nil {
return err
}
}
ms.Meta = m
case ModuleTunManager:
var m TunManagerBroadcastMeta
if has_meta {
if err := json.Unmarshal(meta, &m); err != nil {
return err
}
}
ms.Meta = m
}
return nil
}
func (ms ModuleStatus) Connected() ModuleStatus {
var v = ms
v.State = ServiceStateConnected
return v
}
func (ms ModuleStatus) Disconnected() ModuleStatus {
var v = ms
v.State = ServiceStateConnected
return v
}
func (ms ModuleStatus) String() string {
var s, sErr = json.Marshal(ms)
if sErr != nil {
panic(sErr)
}
return string(s)
}
type Version struct {
Version string `json:"version" bson:"version"`
Commit string `json:"commit" bson:"commit"`
Build int `json:"build" bson:"build"`
}
func MakeVersion(version string, commit string, build string) Version {
var ms Version
ms.Version = version
ms.Commit = commit
build_num, _ := strconv.Atoi(build)
ms.Build = build_num
return ms
}