Skip to content
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

Make the Logger an optional middleware in routers #59

Closed
matheusd opened this issue Jul 3, 2020 · 3 comments · Fixed by #80
Closed

Make the Logger an optional middleware in routers #59

matheusd opened this issue Jul 3, 2020 · 3 comments · Fixed by #80
Labels
enhancement New feature or request
Milestone

Comments

@matheusd
Copy link
Contributor

matheusd commented Jul 3, 2020

Is your feature request related to a problem? Please describe.
Using the current router mux exported by the server package results in endpoints always logging accesses in a specific format. When running a Rosetta server implementation backed by some other pre-existing node server that logs in a different format, logs become slightly harder to read.

Additionally, we might want to offer different forms of logging or offer the option to disable logging altogether to users.

Describe the solution you'd like
Make middlewares (including the currently existing Logger) configurable when calling server.NewRouter.

Describe alternatives you've considered
Another alternative would be disabling logging altogether in the library and having that be a responsibility of users.

@matheusd matheusd added the enhancement New feature or request label Jul 3, 2020
@patrick-ogrady patrick-ogrady added this to the v0.4.0 milestone Jul 19, 2020
@patrick-ogrady
Copy link
Contributor

This has been a common request among a few users of rosetta-sdk-go @matheusd. I've added this to the v0.4.0 release milestone.

Let me know if you'd like to take a stab at working on this!

@matheusd
Copy link
Contributor Author

After taking a second look at the routers, I believe the easiest solution would be to simply drop the existing Cors and Logger middleware from the NewRouter() call and leave it up to the caller to install any middleware they desire. They can be offered as package-level clients and we could add an example on how to use them.

If we really want to offer the ability to add a per-route middleware (such as the current router) the simplest change would be to switch the signature of NewRouter to something like:

type Middleware func (http.Handler, name string)
func NewRouter(middlewares []Middleware, routers ...Route) http.Handler {
...
}

Do either of those seem acceptable?

@patrick-ogrady
Copy link
Contributor

@matheusd Thanks for digging into this! I like the idea of leaving it up to the caller to install any middleware they desire. I think the "logger per route" strategy was the default for the codegen but I don't feel any particular allegiance to it. You could easily accomplish something similar in a custom logger by inspecting the http.Request on the HandlerFunc.

I think having some simple default logger that can be added still makes sense but agree the current one is AWFUL!

This code is all generated, so any changes will need to occur here: https://github.com/coinbase/rosetta-sdk-go/blob/master/templates/server/routers.mustache

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

Successfully merging a pull request may close this issue.

2 participants