1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-04-23 11:07:43 +02:00

38 lines
1.1 KiB
Go
Raw Normal View History

2021-11-24 11:27:23 +08:00
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(route.CorsHandler(cfg.Origin))
2021-11-24 11:27:23 +08:00
}
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.RegisterRoute(router.Group(""))
2021-11-24 11:27:23 +08:00
}
return nil
}