-
Notifications
You must be signed in to change notification settings - Fork 1
/
router.go
30 lines (28 loc) · 1.18 KB
/
router.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package internal
import (
"github.com/ankorstore/yokai-showroom/http-demo/internal/handler"
"github.com/ankorstore/yokai-showroom/http-demo/internal/handler/gopher"
"github.com/ankorstore/yokai-showroom/http-demo/internal/middleware"
"github.com/ankorstore/yokai/fxhttpserver"
"go.uber.org/fx"
)
// Router is used to register the application HTTP middlewares and handlers.
func Router() fx.Option {
return fx.Options(
// authentication middleware
fxhttpserver.AsMiddleware(middleware.NewAuthenticationMiddleware, fxhttpserver.GlobalUse),
// dashboard handler
fxhttpserver.AsHandler("GET", "", handler.NewDashboardHandler),
// gophers CRUD handlers group
fxhttpserver.AsHandlersGroup(
"/gophers",
[]*fxhttpserver.HandlerRegistration{
fxhttpserver.NewHandlerRegistration("GET", "", gopher.NewListGophersHandler),
fxhttpserver.NewHandlerRegistration("POST", "", gopher.NewCreateGopherHandler),
fxhttpserver.NewHandlerRegistration("GET", "/:id", gopher.NewGetGopherHandler),
fxhttpserver.NewHandlerRegistration("PATCH", "/:id", gopher.NewUpdateGopherHandler),
fxhttpserver.NewHandlerRegistration("DELETE", "/:id", gopher.NewDeleteGopherHandler),
},
),
)
}