server.go 634 Bytes
Newer Older
kzkzzzz's avatar
kzkzzzz committed
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
package server

import (
	"github.com/go-kratos/kratos/contrib/registry/consul/v2"
	"github.com/go-kratos/kratos/v2/log"
	"github.com/google/wire"
	"github.com/hashicorp/consul/api"
	"hilo/app/service/mgr/internal/conf"
)

// ProviderSet is server providers.
var (
	ProviderSet = wire.NewSet(NewGRPCServer, NewConsulRegister)
	logHelper   *log.Helper
)

func NewConsulRegister(conf *conf.Consul) *consul.Registry {
	cfg := api.DefaultConfig()
	cfg.Address = conf.Addr
	consulClient, err := api.NewClient(cfg)
	if err != nil {
		panic(err)
	}
	registry := consul.New(consulClient,
		consul.WithHealthCheck(true),
	)
	return registry
}