Skip to content

Commit

Permalink
feat(file) skip writing out empty entities
Browse files Browse the repository at this point in the history
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
```
  • Loading branch information
hbagdi committed Apr 8, 2019
1 parent 8d22848 commit ae38f1b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 24 deletions.
34 changes: 17 additions & 17 deletions file/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,42 @@ package file
import "github.com/hbagdi/go-kong/kong"

type service struct {
kong.Service `yaml:",inline"`
Routes []*route
Plugins []*plugin
kong.Service `yaml:",inline,omitempty"`
Routes []*route `yaml:",omitempty"`
Plugins []*plugin `yaml:",omitempty"`
}

type route struct {
kong.Route `yaml:",inline"`
Plugins []*plugin
kong.Route `yaml:",inline,omitempty"`
Plugins []*plugin `yaml:",omitempty"`
}

type upstream struct {
kong.Upstream `yaml:",inline"`
Targets []*target
kong.Upstream `yaml:",inline,omitempty"`
Targets []*target `yaml:",omitempty"`
}

type target struct {
kong.Target `yaml:",inline"`
kong.Target `yaml:",inline,omitempty"`
}

type certificate struct {
kong.Certificate `yaml:",inline"`
kong.Certificate `yaml:",inline,omitempty"`
}

type plugin struct {
kong.Plugin `yaml:",inline"`
kong.Plugin `yaml:",inline,omitempty"`
}

type consumer struct {
kong.Consumer `yaml:",inline"`
Plugins []*plugin
kong.Consumer `yaml:",inline,omitempty"`
Plugins []*plugin `yaml:",omitempty"`
}

type fileStructure struct {
Services []service
Upstreams []upstream
Certificates []certificate
Plugins []plugin
Consumers []consumer
Services []service `yaml:",omitempty"`
Upstreams []upstream `yaml:",omitempty"`
Certificates []certificate `yaml:",omitempty"`
Plugins []plugin `yaml:",omitempty"`
Consumers []consumer `yaml:",omitempty"`
}
7 changes: 0 additions & 7 deletions kong.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ services:
- https
regex_priority: 0
strip_path: true
plugins: []
plugins: []
- connect_timeout: 60000
host: mockbin.org
name: svc2
Expand All @@ -37,8 +35,6 @@ services:
- https
regex_priority: 0
strip_path: true
plugins: []
plugins: []
- connect_timeout: 60000
host: mockbin.org
name: svc3
Expand All @@ -57,8 +53,6 @@ services:
- https
regex_priority: 0
strip_path: true
plugins: []
plugins: []
upstreams:
- name: upstream1
slots: 10000
Expand Down Expand Up @@ -212,7 +206,6 @@ plugins:
run_on: first
consumers:
- username: harry
plugins: []
- username: yolo
plugins:
- name: rate-limiting
Expand Down

0 comments on commit ae38f1b

Please sign in to comment.