Skip to content

Commit 4e1bf40

Browse files
feat: default endpoint for rule if id same
1 parent cd8db2e commit 4e1bf40

File tree

4 files changed

+21
-17
lines changed

4 files changed

+21
-17
lines changed

README.md

-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ endpoints:
5555

5656
rules:
5757
hello_world:
58-
endpoints:
59-
- hello_world
6058
```
6159
6260
### Full Config

config/config.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,12 @@ func Read(cli CLI) (Raw, error) {
217217
return Raw{}, err
218218
}
219219

220-
for k, v := range raw.Endpoints {
221-
if v.Body_Template == "" {
222-
v.Body_Template = `{{ .Message.Text }}`
223-
raw.Endpoints[k] = v
220+
for endKey := range raw.Endpoints {
221+
for ruleKey, rrule := range raw.Rules {
222+
if ruleKey == endKey {
223+
rrule.Endpoints = append(rrule.Endpoints, endKey)
224+
raw.Rules[ruleKey] = rrule
225+
}
224226
}
225227
}
226228

config/resolve.go config/utils.go

File renamed without changes.

internal/endpoints/endpoints.go

+15-11
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,28 @@ type Endpoint struct {
3232
Config map[string]string
3333
}
3434

35-
func New(req CreateEndpoint) (Endpoint, error) {
36-
if req.Internal && req.InternalID == "" {
35+
func New(r CreateEndpoint) (Endpoint, error) {
36+
if r.Internal && r.InternalID == "" {
3737
return Endpoint{}, fmt.Errorf("internal id is empty")
3838
}
3939

40-
if req.Name == "" {
40+
if r.Name == "" {
4141
return Endpoint{}, fmt.Errorf("name is empty")
4242
}
4343

44+
if r.BodyTemplate == "" {
45+
r.BodyTemplate = "{{ .Message.Text }}"
46+
}
47+
4448
end := Endpoint{
45-
Internal: req.Internal,
46-
InternalID: req.InternalID,
47-
Name: req.Name,
48-
AttachmentDisable: req.AttachmentDisable,
49-
TextDisable: req.TextDisable,
50-
BodyTemplate: req.BodyTemplate,
51-
Kind: req.Kind,
52-
Config: req.Config,
49+
Internal: r.Internal,
50+
InternalID: r.InternalID,
51+
Name: r.Name,
52+
AttachmentDisable: r.AttachmentDisable,
53+
TextDisable: r.TextDisable,
54+
BodyTemplate: r.BodyTemplate,
55+
Kind: r.Kind,
56+
Config: r.Config,
5357
}
5458

5559
_, err := end.Parse()

0 commit comments

Comments
 (0)