-
Notifications
You must be signed in to change notification settings - Fork 1
/
listparams.go
54 lines (46 loc) · 1.58 KB
/
listparams.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
// Copyright 2018 DataArt. All rights reserved.
// Use of this source code is governed by an Apache-style
// license that can be found in the LICENSE file.
package devicehive_go
import (
"errors"
"time"
"github.com/devicehive/devicehive-go/internal/utils"
)
type ListParams struct {
DeviceId string `json:"deviceId,omitempty"`
Start time.Time `json:"start,omitempty"`
End time.Time `json:"end,omitempty"`
Notification string `json:"notification,omitempty"`
Command string `json:"command,omitempty"`
Status string `json:"status,omitempty"`
SortField string `json:"sortField,omitempty"`
SortOrder string `json:"sortOrder,omitempty"`
Take int `json:"take,omitempty"`
Skip int `json:"skip,omitempty"`
Name string `json:"name,omitempty"`
NamePattern string `json:"namePattern,omitempty"`
Login string `json:"login,omitempty"`
LoginPattern string `json:"loginPattern,omitempty"`
NetworkId string `json:"networkId,omitempty"`
NetworkName string `json:"networkName,omitempty"`
UserRole int `json:"role,omitempty"`
UserStatus int `json:"status,omitempty"`
}
func (p *ListParams) Map() (map[string]interface{}, error) {
m := utils.StructToJSONMap(p)
if m == nil {
return nil, errors.New("invalid JSON representation of struct")
}
if p.Start.Unix() < 0 {
delete(m, "start")
} else {
m["start"] = p.Start.Format(timestampLayout)
}
if p.End.Unix() < 0 {
delete(m, "end")
} else {
m["end"] = p.End.Format(timestampLayout)
}
return m, nil
}