Skip to content

Commit ae38f1b

Browse files
committed
feat(file) skip writing out empty entities
Previously, if a consumer didn't have any plugins associated with it, the output YAML would be: ```yaml consumers: - username: harry plugins: [] ``` The `plugins` can be skipped to make the output file more concise. This commits skips writing out entities which are empty: ```yaml consumers: - username: harry ```
1 parent 8d22848 commit ae38f1b

File tree

2 files changed

+17
-24
lines changed

2 files changed

+17
-24
lines changed

file/types.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,42 @@ package file
33
import "github.com/hbagdi/go-kong/kong"
44

55
type service struct {
6-
kong.Service `yaml:",inline"`
7-
Routes []*route
8-
Plugins []*plugin
6+
kong.Service `yaml:",inline,omitempty"`
7+
Routes []*route `yaml:",omitempty"`
8+
Plugins []*plugin `yaml:",omitempty"`
99
}
1010

1111
type route struct {
12-
kong.Route `yaml:",inline"`
13-
Plugins []*plugin
12+
kong.Route `yaml:",inline,omitempty"`
13+
Plugins []*plugin `yaml:",omitempty"`
1414
}
1515

1616
type upstream struct {
17-
kong.Upstream `yaml:",inline"`
18-
Targets []*target
17+
kong.Upstream `yaml:",inline,omitempty"`
18+
Targets []*target `yaml:",omitempty"`
1919
}
2020

2121
type target struct {
22-
kong.Target `yaml:",inline"`
22+
kong.Target `yaml:",inline,omitempty"`
2323
}
2424

2525
type certificate struct {
26-
kong.Certificate `yaml:",inline"`
26+
kong.Certificate `yaml:",inline,omitempty"`
2727
}
2828

2929
type plugin struct {
30-
kong.Plugin `yaml:",inline"`
30+
kong.Plugin `yaml:",inline,omitempty"`
3131
}
3232

3333
type consumer struct {
34-
kong.Consumer `yaml:",inline"`
35-
Plugins []*plugin
34+
kong.Consumer `yaml:",inline,omitempty"`
35+
Plugins []*plugin `yaml:",omitempty"`
3636
}
3737

3838
type fileStructure struct {
39-
Services []service
40-
Upstreams []upstream
41-
Certificates []certificate
42-
Plugins []plugin
43-
Consumers []consumer
39+
Services []service `yaml:",omitempty"`
40+
Upstreams []upstream `yaml:",omitempty"`
41+
Certificates []certificate `yaml:",omitempty"`
42+
Plugins []plugin `yaml:",omitempty"`
43+
Consumers []consumer `yaml:",omitempty"`
4444
}

kong.yaml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ services:
1717
- https
1818
regex_priority: 0
1919
strip_path: true
20-
plugins: []
21-
plugins: []
2220
- connect_timeout: 60000
2321
host: mockbin.org
2422
name: svc2
@@ -37,8 +35,6 @@ services:
3735
- https
3836
regex_priority: 0
3937
strip_path: true
40-
plugins: []
41-
plugins: []
4238
- connect_timeout: 60000
4339
host: mockbin.org
4440
name: svc3
@@ -57,8 +53,6 @@ services:
5753
- https
5854
regex_priority: 0
5955
strip_path: true
60-
plugins: []
61-
plugins: []
6256
upstreams:
6357
- name: upstream1
6458
slots: 10000
@@ -212,7 +206,6 @@ plugins:
212206
run_on: first
213207
consumers:
214208
- username: harry
215-
plugins: []
216209
- username: yolo
217210
plugins:
218211
- name: rate-limiting

0 commit comments

Comments
 (0)