-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstructs.go
157 lines (142 loc) · 3.63 KB
/
structs.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package main
import (
"fmt"
"os"
"strconv"
"strings"
)
// ValidCommands will save all type of commands
type ValidCommands string
const (
// Add will create a new subscription
Add ValidCommands = "add"
// Delete will remove a client and his subs
Delete ValidCommands = "delete"
// Delete will remove a client and his subs
Mail ValidCommands = "mail"
)
func (e ValidCommands) String() string {
commands := [...]string{"add", "delete", "mail"}
x := string(e)
for _, v := range commands {
if strings.ToLower(v) == strings.ToLower(x) {
return strings.ToLower(v)
}
}
return ""
}
// Row is used to save the csv format
type Row struct {
UserID string
IDSubscripcion string
Nombre string
Item string
Leyenda string
FechaInicio string
FechaInicioCiclo string
IDPago string
CodigoPromo string
NombreUser string
ApellidoPaterno string
Email string
TelefonoTelmex string
FormaDePago string
}
func (r *Row) toArray(statusCode string, message string) []string {
return []string{
r.UserID,
r.IDSubscripcion,
r.Nombre,
r.Item,
r.Leyenda,
r.FechaInicio,
r.FechaInicioCiclo,
r.IDPago,
r.CodigoPromo,
r.NombreUser,
r.ApellidoPaterno,
r.Email,
r.TelefonoTelmex,
r.FormaDePago,
statusCode,
message,
}
}
// MailRow is the struct for the csv
type MailRow struct {
Email string
GamificationID string
}
func (r *MailRow) toArray(statusCode string, message string) []string {
return []string{
r.Email,
r.GamificationID,
statusCode,
message,
}
}
// NewMailRow is the struct for mail csv
func NewMailRow(element []string) *MailRow {
return &MailRow{
Email: definedOrEmpty(element, 0),
GamificationID: definedOrEmpty(element, 1),
}
}
// NewRow create and object from a string array
func NewRow(element []string) *Row {
return &Row{
UserID: definedOrEmpty(element, 0),
IDSubscripcion: definedOrEmpty(element, 1),
Nombre: definedOrEmpty(element, 2),
Item: definedOrEmpty(element, 3),
Leyenda: definedOrEmpty(element, 4),
FechaInicio: definedOrEmpty(element, 5),
FechaInicioCiclo: definedOrEmpty(element, 6),
IDPago: definedOrEmpty(element, 7),
CodigoPromo: definedOrEmpty(element, 8),
NombreUser: definedOrEmpty(element, 9),
ApellidoPaterno: definedOrEmpty(element, 10),
Email: definedOrEmpty(element, 11),
TelefonoTelmex: definedOrEmpty(element, 12),
FormaDePago: definedOrEmpty(element, 13),
}
}
// Args is used to save the args been used
type Args struct {
Command string // First argument with file path
Endpoint string // Second argument with the WSDL domain
GoRoutines int // Third argument with amount of routines
OutputPath string // Argument with the path to save the filed rows
AuthToken string // Basic token for wsdl
NCDomain string // Domain for NC instance
NCUser string // user for NC instance
NCToken string // Basic token for wsdl
}
// GetArgs will retrieve the command line arguments
func GetArgs(args []string) Args {
if len(args) < 7 {
fmt.Printf("Not enough arguments: %v\n", args)
os.Exit(0)
}
routines, _ := strconv.Atoi(args[2])
return Args{
Command: args[0],
Endpoint: args[1],
GoRoutines: routines,
OutputPath: args[3],
AuthToken: args[4],
NCDomain: args[5],
NCUser: args[6],
NCToken: args[7],
}
}
func definedOrEmpty(arr []string, pos int) string {
if len(arr) >= pos+1 {
return arr[pos]
}
return ""
}
// EngResponse used to track en engagement responses
type EngResponse struct {
Status string `json:"status,omitempty"`
}