Skip to content

Commit

Permalink
feat: add flat error support to config update
Browse files Browse the repository at this point in the history
  • Loading branch information
rainest committed Feb 3, 2023
1 parent ab5b18a commit a61b0d5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@
`ConfigService`, now part of `kong.Client`) now has the response signature
`([]byte, error)` instead of `error`. The byte slice is the config response
body. The error is unchanged.
- **Breaking change:** `ReloadDeclarativeRawConfig()` now requires a
`flattenErrors` boolean argument. When `true`, requests will include
`flatten_errors=1` in the query string, to activate the functionality added
in https://github.com/Kong/kong/pull/10161.
[#273](https://github.com/Kong/go-kong/pull/273)

## [v0.36.0]
Expand Down
15 changes: 13 additions & 2 deletions kong/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,15 +386,26 @@ func (c *Client) ReloadDeclarativeRawConfig(
ctx context.Context,
config io.Reader,
checkHash bool,
flattenErrors bool,
) ([]byte, error) {
type sendConfigParams struct {
CheckHash int `url:"check_hash"`
CheckHash int `url:"check_hash"`
FlattenErrors int `url:"flatten_errors"`
}
var checkHashI int
if checkHash {
checkHashI = 1
}
req, err := c.NewRequest("POST", "/config", sendConfigParams{CheckHash: checkHashI}, config)
var flattenErrorsI int
if flattenErrors {
flattenErrorsI = 1
}
req, err := c.NewRequest(
"POST",
"/config",
sendConfigParams{CheckHash: checkHashI, FlattenErrors: flattenErrorsI},
config,
)
if err != nil {
return nil, fmt.Errorf("creating new HTTP request for /config: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion kong/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ func TestReloadDeclarativeRawConfig(t *testing.T) {
b, err := json.Marshal(tt.config)
require.NoError(t, err)

body, err := client.ReloadDeclarativeRawConfig(ctx, bytes.NewBuffer(b), true)
body, err := client.ReloadDeclarativeRawConfig(ctx, bytes.NewBuffer(b), true, true)
stringBody := string(body)
if stringBody == "" {
t.Errorf("wat")
Expand Down

0 comments on commit a61b0d5

Please sign in to comment.