-
Notifications
You must be signed in to change notification settings - Fork 104
Expand file tree
/
Copy pathschedule.go
More file actions
51 lines (46 loc) · 1.21 KB
/
Copy pathschedule.go
File metadata and controls
51 lines (46 loc) · 1.21 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
package jpushclient
import (
"encoding/json"
"time"
)
type Schedule struct {
Cid string `json:"cid"`
Name string `json:"name"`
Enabled bool `json:"enabled"`
Trigger map[string]interface{} `json:"trigger"`
Push *PayLoad `json:"push"`
}
func NewSchedule(name,cid string, enabled bool, push *PayLoad) *Schedule {
return &Schedule{
Cid: cid,
Name: name,
Enabled: enabled,
Push: push,
}
}
func (s *Schedule) SingleTrigger(t time.Time) {
s.Trigger = map[string]interface{}{
"single": map[string]interface{}{
"time": t.Format("2006-01-02 15:04:05"),
},
}
}
func (s *Schedule) PeriodicalTrigger(start time.Time, end time.Time, time time.Time, timeUnit string, frequency int, point []string) {
s.Trigger = map[string]interface{}{
"periodical": map[string]interface{}{
"start": start.Format("2006-01-02 15:04:05"),
"end": end.Format("2006-01-02 15:04:05"),
"time": start.Format("15:04:05"),
"time_unit": timeUnit,
"frequency": frequency,
"point": point,
},
}
}
func (this *Schedule) ToBytes() ([]byte, error) {
content, err := json.Marshal(this)
if err != nil {
return nil, err
}
return content, nil
}