Skip to content

Commit 8298234

Browse files
committed
opt.: push title: string -> PushFormat
1 parent 45dbd8e commit 8298234

File tree

5 files changed

+24
-17
lines changed

5 files changed

+24
-17
lines changed

cmd/serve.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ func init() {
2121
EnvVars: []string{"SBM_ADDR"},
2222
},
2323
&cli.StringFlag{
24-
Name: "crt",
24+
Name: "crt",
2525
Aliases: []string{"c"},
26-
Usage: "TLS certificate file path",
26+
Usage: "TLS certificate file path",
2727
EnvVars: []string{"SBM_TLS_CRT"},
2828
},
2929
&cli.StringFlag{
30-
Name: "key",
30+
Name: "key",
3131
Aliases: []string{"k"},
32-
Usage: "TLS key file path",
32+
Usage: "TLS key file path",
3333
EnvVars: []string{"SBM_TLS_KEY"},
3434
},
3535
},
@@ -40,7 +40,7 @@ func handleServe(ctx *cli.Context) error {
4040
webConfig := &model.WebConfig{
4141
Addr: ctx.String("addr"),
4242
Cert: ctx.String("crt"),
43-
Key: ctx.String("key"),
43+
Key: ctx.String("key"),
4444
}
4545
runner.Start(webConfig)
4646
return nil

model/config.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ var (
122122
"action": "send_group_msg",
123123
"params": map[string]interface{}{
124124
"group_id": 123456789,
125-
"message": res.PushFormatNameLocator +
126-
"\n" +
127-
res.PushFormatMsgLocator,
125+
"message": res.PushFormatNameLocator +
126+
"\n" +
127+
res.PushFormatMsgLocator,
128128
},
129129
}
130130
defaultWekhookBodyBytes, _ = json.Marshal(defaultWebhookBody)

model/push.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ func (pf PushFormat) Format(args []*PushPair) string {
7979
ss = append(ss, kv)
8080
}
8181
msgReplaced := strings.Replace(
82-
string(pf),
83-
res.PushFormatMsgLocator,
84-
strings.Join(ss, `\n`),
82+
string(pf),
83+
res.PushFormatMsgLocator,
84+
strings.Join(ss, `\n`),
8585
1,
8686
)
8787
nameReplaced := strings.Replace(
@@ -107,17 +107,18 @@ type PushIface interface {
107107

108108
type PushIfaceIOS struct {
109109
Token string `json:"token"`
110-
Title string `json:"title"`
110+
Title PushFormat `json:"title"`
111111
Content PushFormat `json:"content"`
112112
BodyRegex string `json:"body_regex"`
113113
Code int `json:"code"`
114114
}
115115

116116
func (p PushIfaceIOS) push(args []*PushPair) error {
117117
content := p.Content.Format(args)
118+
title := p.Title.Format(args)
118119
body := map[string]string{
119120
"token": p.Token,
120-
"title": p.Title,
121+
"title": title,
121122
"content": content,
122123
}
123124
bodyBytes, err := json.Marshal(body)
@@ -185,15 +186,21 @@ func (p PushIfaceWebhook) push(args []*PushPair) error {
185186

186187
type PushIfaceServerChan struct {
187188
SCKey string `json:"sckey"`
188-
Title string `json:"title"`
189+
Title PushFormat `json:"title"`
189190
Desp PushFormat `json:"desp"`
190191
BodyRegex string `json:"body_regex"`
191192
Code int `json:"code"`
192193
}
193194

194195
func (p PushIfaceServerChan) push(args []*PushPair) error {
195196
desp := p.Desp.Format(args)
196-
url := fmt.Sprintf("https://sctapi.ftqq.com/%s.send?title=%s&desp=%s", p.SCKey, p.Title, desp)
197+
title := p.Title.Format(args)
198+
url := fmt.Sprintf(
199+
"https://sctapi.ftqq.com/%s.send?title=%s&desp=%s",
200+
p.SCKey,
201+
title,
202+
desp,
203+
)
197204
resp, code, err := http.Do("GET", url, nil, nil)
198205
if err != nil {
199206
return err

model/web.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ func (wc *WebConfig) HaveTLS() bool {
1919
return false
2020
}
2121
return true
22-
}
22+
}

res/res.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const (
3636
DefaultInterval = time.Second * 7
3737
MaxInterval = time.Second * 10
3838

39-
PushFormatMsgLocator = "{{msg}}"
39+
PushFormatMsgLocator = "{{msg}}"
4040
PushFormatNameLocator = "{{name}}"
4141
)
4242

0 commit comments

Comments
 (0)