Skip to content

Commit

Permalink
chore: fix hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
pmalek committed Nov 5, 2024
1 parent 54c2c3b commit 68361d1
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 32 deletions.
4 changes: 2 additions & 2 deletions .speakeasy/gen.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ management:
docVersion: 0.0.1
speakeasyVersion: 1.428.0
generationVersion: 2.447.4
releaseVersion: 0.1.4
configChecksum: 3cacebf193ce554f49ccc3010b5909cb
releaseVersion: 0.1.5
configChecksum: 842844ce7940b9fa7ce8ff52e625d2fe
features:
go:
additionalDependencies: 0.1.0
Expand Down
2 changes: 1 addition & 1 deletion .speakeasy/gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ generation:
oAuth2ClientCredentialsEnabled: false
oAuth2PasswordEnabled: false
go:
version: 0.1.4
version: 0.1.5
additionalDependencies: {}
allowUnknownFieldsInWeakUnions: false
clientServerStatusCodesAsErrors: true
Expand Down
21 changes: 3 additions & 18 deletions internal/hooks/httpdump.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,12 @@ import (
)

// HTTPDumpRequestHook is a hook that dumps the request to stdout.
type HTTPDumpRequestHook struct {
Enabled bool
}
type HTTPDumpRequestHook struct{}

var _ beforeRequestHook = (*HTTPDumpRequestHook)(nil)

// BeforeRequest dumps the request to stdout if enabled.
func (i *HTTPDumpRequestHook) BeforeRequest(hookCtx BeforeRequestContext, req *http.Request) (*http.Request, error) {
if !i.Enabled {
return req, nil
}
if req == nil {
return nil, nil
}
Expand All @@ -33,32 +28,22 @@ func (i *HTTPDumpRequestHook) BeforeRequest(hookCtx BeforeRequestContext, req *h
}

// HTTPDumpResponseHook is a hook that dumps the response to stdout.
type HTTPDumpResponseHook struct {
Enabled bool
}
type HTTPDumpResponseHook struct{}

var _ afterSuccessHook = (*HTTPDumpResponseHook)(nil)

// AfterSuccess dumps the response to stdout if enabled.
func (i *HTTPDumpResponseHook) AfterSuccess(hookCtx AfterSuccessContext, res *http.Response) (*http.Response, error) {
if !i.Enabled {
return res, nil
}
return dumpResponse(res), nil
}

// HTTPDumpResponseErrorHook is a hook that dumps the error response to stdout.
type HTTPDumpResponseErrorHook struct {
Enabled bool
}
type HTTPDumpResponseErrorHook struct{}

var _ afterErrorHook = (*HTTPDumpResponseErrorHook)(nil)

// AfterError dumps the error response to stdout if enabled.
func (i *HTTPDumpResponseErrorHook) AfterError(hookCtx AfterErrorContext, res *http.Response, err error) (*http.Response, error) {
if !i.Enabled {
return res, nil
}
if err != nil {
fmt.Printf("Error: %v\n", err)
}
Expand Down
19 changes: 10 additions & 9 deletions internal/hooks/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ func initHooks(h *Hooks) {

h.registerBeforeRequestHook(&APIURLRequestHook{})

h.registerBeforeRequestHook(&HTTPDumpRequestHook{
Enabled: os.Getenv("KONNECT_SDK_HTTP_DUMP_REQUEST") == "true",
})
if os.Getenv("KONNECT_SDK_HTTP_DUMP_REQUEST") == "true" {
h.registerBeforeRequestHook(&HTTPDumpRequestHook{})
}

h.registerAfterSuccessHook(&HTTPDumpResponseHook{
Enabled: os.Getenv("KONNECT_SDK_HTTP_DUMP_RESPONSE") == "true",
})
h.registerAfterErrorHook(&HTTPDumpResponseErrorHook{
Enabled: os.Getenv("KONNECT_SDK_HTTP_DUMP_RESPONSE_ERROR") == "true",
})
if os.Getenv("KONNECT_SDK_HTTP_DUMP_RESPONSE") == "true" {
h.registerAfterSuccessHook(&HTTPDumpResponseHook{})
}

if os.Getenv("KONNECT_SDK_HTTP_DUMP_RESPONSE_ERROR") == "true" {
h.registerAfterErrorHook(&HTTPDumpResponseErrorHook{})
}
}
4 changes: 2 additions & 2 deletions sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,9 @@ func New(opts ...SDKOption) *SDK {
sdkConfiguration: sdkConfiguration{
Language: "go",
OpenAPIDocVersion: "0.0.1",
SDKVersion: "0.1.4",
SDKVersion: "0.1.5",
GenVersion: "2.447.4",
UserAgent: "speakeasy-sdk/go 0.1.4 2.447.4 0.0.1 github.com/Kong/sdk-konnect-go",
UserAgent: "speakeasy-sdk/go 0.1.5 2.447.4 0.0.1 github.com/Kong/sdk-konnect-go",
Hooks: hooks.New(),
},
}
Expand Down

0 comments on commit 68361d1

Please sign in to comment.