-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
81 lines (70 loc) · 2.14 KB
/
types.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
package main
import (
"time"
"gomodules.xyz/mailer"
)
type ContactData struct {
Name string
Product string
}
type Contact struct {
Email string `csv:"email"`
Data string `csv:"data"` // json format
Stop bool `csv:"stop"`
Step_0_Timestamp Timestamp `csv:"s0_timestamp"`
Step_0_WaitForCondition bool `csv:"s0_wait_for_cond"`
Step_0_Done bool `csv:"s0_done"`
Step_1_Timestamp Timestamp `csv:"s1_timestamp"`
Step_1_WaitForCondition bool `csv:"s1_wait_for_cond"`
Step_1_Done bool `csv:"s1_done"`
Step_2_Timestamp Timestamp `csv:"s2_timestamp"`
Step_2_WaitForCondition bool `csv:"s2_wait_for_cond"`
Step_2_Done bool `csv:"s2_done"`
Step_3_Timestamp Timestamp `csv:"s3_timestamp"`
Step_3_WaitForCondition bool `csv:"s3_wait_for_cond"`
Step_3_Done bool `csv:"s3_done"`
Step_4_Timestamp Timestamp `csv:"s4_timestamp"`
Step_4_WaitForCondition bool `csv:"s4_wait_for_cond"`
Step_4_Done bool `csv:"s4_done"`
}
type Timestamp struct {
time.Time
}
func (date *Timestamp) MarshalCSV() (string, error) {
if date.IsZero() {
return "", nil
}
return date.Time.UTC().Format("01/02/2006 15:04:05"), nil
}
func (date *Timestamp) String() string {
return date.Time.UTC().Format(time.RFC3339) // Redundant, just for example
}
func (date *Timestamp) UnmarshalCSV(csv string) (err error) {
if csv != "" {
date.Time, err = time.Parse("01/02/2006 15:04:05", csv)
}
return err
}
type DripCampaign struct {
Steps []DripCampaignStep
}
type DripCampaignStep struct {
WaitTime time.Duration
Mailer mailer.Mailer
}
func (dc DripCampaign) Prepare(c *Contact, t time.Time) {
for idx, step := range dc.Steps {
switch idx {
case 0:
c.Step_0_Timestamp = Timestamp{t.Add(step.WaitTime)}
case 1:
c.Step_1_Timestamp = Timestamp{t.Add(step.WaitTime)}
case 2:
c.Step_2_Timestamp = Timestamp{t.Add(step.WaitTime)}
case 3:
c.Step_3_Timestamp = Timestamp{t.Add(step.WaitTime)}
case 4:
c.Step_4_Timestamp = Timestamp{t.Add(step.WaitTime)}
}
}
}