-
-
Notifications
You must be signed in to change notification settings - Fork 57
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/#issue284 #325
base: main
Are you sure you want to change the base?
Feat/#issue284 #325
Changes from 2 commits
c1b3d3f
cf2e7bd
12b8659
c49852e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,10 @@ type Server struct { | |
// For example, it allows OPTIONS /foo even if it is not declared (only GET /foo is declared). | ||
corsMiddleware func(http.Handler) http.Handler | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you still need this then? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True, as it is not exposed, we can remove it, no need for deprecation notice! |
||
|
||
// globalMiddlewares is used to store the options | ||
// that will be applied on ALL routes. | ||
globalMiddlewares []func(http.Handler) http.Handler | ||
|
||
// routeOptions is used to store the options | ||
// that will be applied of the route. | ||
routeOptions []func(*BaseRoute) | ||
|
@@ -171,22 +175,30 @@ func WithTemplateFS(fs fs.FS) func(*Server) { | |
return func(c *Server) { c.fs = fs } | ||
} | ||
|
||
// WithCorsMiddleware registers a middleware to handle CORS. | ||
// It is not handled like other middlewares with [Use] because it applies routes that are not registered. | ||
// For example: | ||
|
||
// WithGlobalMiddleware adds middleware(s) that will be executed on ALL requests, | ||
// even those that don't match any registered routes. | ||
// For example, to add CORS middleware: | ||
// | ||
// import "github.com/rs/cors" | ||
// | ||
// s := fuego.NewServer( | ||
// WithCorsMiddleware(cors.New(cors.Options{ | ||
// WithGlobalMiddleware(cors.New(cors.Options{ | ||
// AllowedOrigins: []string{"*"}, | ||
// AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"}, | ||
// AllowedHeaders: []string{"*"}, | ||
// AllowCredentials: true, | ||
// }).Handler) | ||
// }).Handler), | ||
// ) | ||
func WithGlobalMiddleware(middlewares ...func(http.Handler) http.Handler) func(*Server) { | ||
return func(c *Server) { | ||
c.globalMiddlewares = append(c.globalMiddlewares, middlewares...) | ||
} | ||
} | ||
|
||
// WithCorsMiddleware is deprecated: Use WithGlobalMiddleware instead. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use the same syntax than all other deprecated notices, the one understood by Go editors and godoc : skip line then write Also, please reference |
||
func WithCorsMiddleware(corsMiddleware func(http.Handler) http.Handler) func(*Server) { | ||
return func(c *Server) { c.corsMiddleware = corsMiddleware } | ||
return WithGlobalMiddleware(corsMiddleware) | ||
} | ||
|
||
// WithGlobalResponseTypes adds default response types to the server. | ||
|
@@ -441,4 +453,4 @@ func WithLoggingMiddleware(loggingConfig LoggingConfig) func(*Server) { | |
s.loggingConfig.RequestIDFunc = loggingConfig.RequestIDFunc | ||
} | ||
} | ||
} | ||
} |
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.
Why such a change?
You could add a commit if it's about formatting files