mirror of
https://github.com/go-micro/go-micro.git
synced 2025-11-29 21:47:44 +02:00
[feature] dashboard (#2361)
This commit is contained in:
39
cmd/dashboard/handler/handler.go
Normal file
39
cmd/dashboard/handler/handler.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"github.com/asim/go-micro/cmd/dashboard/v4/config"
|
||||
"github.com/asim/go-micro/cmd/dashboard/v4/handler/account"
|
||||
handlerclient "github.com/asim/go-micro/cmd/dashboard/v4/handler/client"
|
||||
"github.com/asim/go-micro/cmd/dashboard/v4/handler/registry"
|
||||
"github.com/asim/go-micro/cmd/dashboard/v4/handler/route"
|
||||
"github.com/asim/go-micro/cmd/dashboard/v4/handler/statistics"
|
||||
"github.com/asim/go-micro/cmd/dashboard/v4/web"
|
||||
"github.com/gin-gonic/gin"
|
||||
"go-micro.dev/v4/client"
|
||||
)
|
||||
|
||||
type Options struct {
|
||||
Client client.Client
|
||||
Router *gin.Engine
|
||||
}
|
||||
|
||||
func Register(opts Options) error {
|
||||
router := opts.Router
|
||||
if err := web.RegisterRoute(router); err != nil {
|
||||
return err
|
||||
}
|
||||
if cfg := config.GetServerConfig().CORS; cfg.Enable {
|
||||
router.Use(CorsHandler(cfg.Origin))
|
||||
}
|
||||
authRouter := router.Group("").Use(AuthRequired())
|
||||
for _, r := range []route.Registrar{
|
||||
account.NewRouteRegistrar(),
|
||||
handlerclient.NewRouteRegistrar(opts.Client, opts.Client.Options().Registry),
|
||||
registry.NewRouteRegistrar(opts.Client.Options().Registry),
|
||||
statistics.NewRouteRegistrar(opts.Client.Options().Registry),
|
||||
} {
|
||||
r.RegisterNonAuthRoute(router)
|
||||
r.RegisterAuthRoute(authRouter)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user