forked from micromdm/mdm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmarshal_json.template
54 lines (54 loc) · 1.17 KB
/
marshal_json.template
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
func (c *CommandRequest) UnmarshalJSON(d []byte) error {
var j struct {
RequestType string `json:"request_type"`
}
if err := json.Unmarshal(d, &j); err != nil {
return err
}
switch j.RequestType {
case "ProfileList",
"ProvisioningProfileList",
"CertificateList",
"SecurityInfo",
"StopMirroring",
"ClearRestrictionsPassword",
"LogOutUser",
"DisableLostMode",
"DeviceLocation",
"ManagedMediaList",
"OSUpdateStatus",
"DeviceConfigured",
"AvailableOSUpdates",
"Restrictions",
"UserList",
"ShutDownDevice",
"RestartDevice":
var x struct {
RequestType string `json:"request_type"`
UDID string `json:"udid"`
}
if err := json.Unmarshal(d, &x); err != nil {
return err
}
c.RequestType = x.RequestType
c.UDID = x.UDID
return nil
{{ range . }}
case "{{.Case}}":
var x struct {
RequestType string `json:"request_type"`
UDID string `json:"udid"`
{{.Case}}
}
if err := json.Unmarshal(d, &x); err != nil {
return err
}
c.RequestType = x.RequestType
c.UDID = x.UDID
c.{{.Case}} = x.{{.Case}}
return nil
{{ end }}
default:
return fmt.Errorf("mdm: unknown request_type %s", j.RequestType)
}
}