Пример #1
0
func web(ctx *cli.Context) {
	opts := []gweb.Option{
		gweb.Name("go.micro.web.discovery"),
		gweb.Handler(whandler.Router()),
	}

	opts = append(opts, helper.WebOpts(ctx)...)

	templateDir := "discovery/templates"
	if dir := ctx.GlobalString("html_dir"); len(dir) > 0 {
		templateDir = dir
	}

	whandler.Init(
		templateDir,
		proto.NewDiscoveryClient("go.micro.srv.discovery", *cmd.DefaultOptions().Client),
		proto2.NewRegistryClient("go.micro.srv.discovery", *cmd.DefaultOptions().Client),
	)

	service := gweb.NewService(opts...)

	if err := service.Run(); err != nil {
		log.Fatal(err)
	}
}
Пример #2
0
func newPlatform(opts ...Option) Discovery {
	opt := Options{
		Discovery: true,
	}

	for _, o := range opts {
		o(&opt)
	}

	if opt.Registry == nil {
		opt.Registry = registry.DefaultRegistry
	}

	if opt.Client == nil {
		opt.Client = client.DefaultClient
	}

	if opt.Interval == time.Duration(0) {
		opt.Interval = time.Second * 30
	}

	return &platform{
		opts:       opt,
		heartbeats: make(map[string]*proto.Heartbeat),
		cache:      make(map[string][]*registry.Service),
		reg:        proto2.NewRegistryClient("go.micro.srv.discovery", opt.Client),
	}
}