1
0
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:
Johnson C
2021-11-24 11:27:23 +08:00
committed by GitHub
parent 90b3e4af0b
commit 70d2bd8a6b
32 changed files with 2606 additions and 0 deletions

View 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
}