-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmsexec.go
67 lines (55 loc) · 1.69 KB
/
smsexec.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
package delayed_job
import (
"errors"
"flag"
)
var (
smsExecBatchSupport string
smsExecWorkDirectory string
smsExecCommand string
smsExecArguments string
smsExecPrompt string
)
func init() {
flag.StringVar(&smsExecBatchSupport, "sms.exec.batch_support", "", "")
flag.StringVar(&smsExecWorkDirectory, "sms.exec.work_directory", "", "")
flag.StringVar(&smsExecCommand, "sms.exec.command", "", "")
flag.StringVar(&smsExecArguments, "sms.exec.arguments", "", "")
flag.StringVar(&smsExecPrompt, "sms.exec.prompt", "", "")
}
func BatchSendByExec(args interface{}, phones []string, content string) error {
if len(phones) == 0 {
return nil
}
params := map[string]interface{}{
"args": args,
"phones": phones,
"phone": phones[0],
"content": content,
}
text := readStringWith(args, "sms.exec.command", smsExecCommand)
command, e := genText(text, params)
if nil != e {
return errors.New("failed to merge 'command' with params, " + e.Error())
}
var arguments []string
text = readStringWith(args, "sms.exec.arguments", smsExecArguments)
if smsExecArguments != "" {
text, e := genText(smsExecArguments, params)
if nil != e {
return errors.New("failed to merge 'arguments' with params, " + e.Error())
}
arguments = SplitLines(text)
}
handler := &execHandler{
work_directory: readStringWith(args, "sms.exec.work_directory", smsExecWorkDirectory),
prompt: readStringWith(args, "sms.exec.prompt", smsExecPrompt),
command: command,
arguments: arguments,
// environments: environments,
}
return handler.Perform()
}
func SendByExec(args interface{}, phone, content string) error {
return BatchSendByExec(args, []string{phone}, content)
}