Skip to content

Commit

Permalink
Merge pull request #100 from jortel/support-middleware
Browse files Browse the repository at this point in the history
Web handler enhancements.
  • Loading branch information
jortel authored Sep 27, 2021
2 parents 85e6c0e + a20c937 commit 858e8b9
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
1 change: 1 addition & 0 deletions pkg/condition/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions pkg/inventory/web/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ import (
type RequestHandler interface {
// Add routes to the `gin` router.
AddRoutes(*gin.Engine)
// List resources in a REST collection.
List(*gin.Context)
// Get a specific REST resource.
Get(*gin.Context)
}

//
Expand Down
5 changes: 4 additions & 1 deletion pkg/inventory/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type WebServer struct {
// Start the web-server.
// Initializes `gin` with routes and CORS origins.
// Creates an http server to handle TLS
func (w *WebServer) Start() {
func (w *WebServer) Start(middleware ...gin.HandlerFunc) {
router := gin.Default()
router.Use(cors.New(cors.Config{
AllowMethods: []string{"GET"},
Expand All @@ -51,6 +51,9 @@ func (w *WebServer) Start() {
AllowCredentials: true,
MaxAge: 12 * time.Hour,
}))
for _, h := range middleware {
router.Use(h)
}
w.buildOrigins()
w.addRoutes(router)
if w.TLS.Enabled {
Expand Down

0 comments on commit 858e8b9

Please sign in to comment.