-
Notifications
You must be signed in to change notification settings - Fork 78
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
httpbp: force http servers to define the methods their endpoints support #229
Conversation
…ually create an http server
// Use the http.Method* constants from "net/http" for the values in this slice | ||
// to ensure that you are using methods that are supported and in the format | ||
// we expect. | ||
Methods []string |
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.
🔕 Would it be better to have this be 2 values? Method string
which is required and AdditionalMethods []string
which is an optional list of additional HTTP methods that your endpoint supports? I feel like most cases just want to support a single method so this might be a better option on average?
wrappers := make([]Middleware, 0, len(f.middlewares)+len(middlewares)) | ||
func (f httpHandlerFactory) NewHandler(endpoint Endpoint) http.Handler { | ||
wrappers := make([]Middleware, 0, len(f.middlewares)+len(endpoint.Middlewares)+1) | ||
wrappers = append(wrappers, SupportedMethods(endpoint.Methods[0], endpoint.Methods[1:]...)) |
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.
note, this will panic if you pass in an empty slice... let it! We already check this earlier by calling endpoint.Validate
wrappers := make([]Middleware, 0, len(f.middlewares)+len(middlewares)) | ||
func (f httpHandlerFactory) NewHandler(endpoint Endpoint) http.Handler { | ||
wrappers := make([]Middleware, 0, len(f.middlewares)+len(endpoint.Middlewares)+1) | ||
wrappers = append(wrappers, SupportedMethods(endpoint.Methods[0], endpoint.Methods[1:]...)) |
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.
🔕 til this won't cause panic when the slice contains one item: https://play.golang.org/p/HtkVu8laHF_n
No description provided.