-
-
Notifications
You must be signed in to change notification settings - Fork 152
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
feat: ability to fetch router from huma context #82
Conversation
This allows us to query the router for information. I've added a GetOperation method so we can query for information about a given operation. This is useful in hypermedia APIs because it allows us to link across different endpoints without having to hardwire paths. Instead, the cross-referencing is done via operation id.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just a couple minor things!
@@ -34,6 +37,15 @@ func GetConn(ctx context.Context) net.Conn { | |||
return nil | |||
} | |||
|
|||
// GetRouter gets the `*Router` handling API requests | |||
func GetRouter(ctx context.Context) *Router { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be used to greatly simplify the code in #80? The context would already have the router injected and there's no need to pass it around everywhere right? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly. Note that several tests don't have a router (in which case I send in nil
). But since the GetRouter
function returns nil
when it can't find a Router
in the context, then it should actually be pretty equivalent. I agree, it would simplify the code. The issue here was that I wanted to provide you with independent PRs in case you decided to reject any. So that's why I don't leverage this in #80. But if you want me to refactor it once this PR is merged, I can certainly do that.
Co-authored-by: Daniel G. Taylor <danielgtaylor@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
This allows us to query the router for information. I've added a GetOperation method so we can query for information about a given operation. This is useful in hypermedia APIs because it allows us to link across different endpoints without having to hardwire paths. Instead, the cross-referencing is done via operation id.