8000 feat: Allow configuring hooks via Kong's functional options by boblail · Pull Request #511 · alecthomas/kong · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: Allow configuring hooks via Kong's functional options #511

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

boblail
Copy link
Contributor
@boblail boblail commented Mar 20, 2025

Lets you pass kong.WithBeforeApply along with a function that supports dynamic bindings to register a BeforeApply hook without tying it directly to a node in the schema.

Also updates the README.md to list a table of hooks with their meanings.

options.go Outdated
@@ -123,6 +123,15 @@ func PostBuild(fn func(*Kong) error) Option {
})
}

func BeforeApplyHook(fn hook) Option {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was literally just wanting this functionality yesterday, so +1 from me.

I'd prefer this to be named WithBeforeApply, and fn will have to be any to correctly match any function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

What do you think of removing https://github.com/alecthomas/kong/blob/master/hooks.go and naming these functional options BeforeReset, BeforeResolve, etc?

@boblail boblail force-pushed the lail/register-hooks-via-Options branch from 11f88bf to ccac06b Compare March 21, 2025 22:26
@boblail boblail marked this pull request as ready for review March 21, 2025 22:27
Lets you pass `kong.WithBeforeApply` along with a function that supports dynamic bindings to register a `BeforeApply` hook without tying it directly to a node in the schema.

Co-authored-by: Sutina Wipawiwat <swipawiwat@squareup.com>
@boblail boblail force-pushed the lail/register-hooks-via-Options branch from ccac06b to afbf0c1 Compare March 21, 2025 22:32
@boblail boblail requested a review from alecthomas March 21, 2025 22:33
Copy link
Owner
@alecthomas alecthomas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks!

@alecthomas alecthomas merged commit 78d4066 into alecthomas:master Mar 22, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0