server.go 650 Bytes
Newer Older
kzkzzzz's avatar
kzkzzzz committed
1 2 3
package server

import (
kzkzzzz's avatar
kzkzzzz committed
4
	"github.com/go-kratos/kratos/contrib/registry/consul/v2"
kzkzzzz's avatar
kzkzzzz committed
5 6
	"github.com/go-kratos/kratos/v2/log"
	"github.com/google/wire"
kzkzzzz's avatar
kzkzzzz committed
7 8
	"github.com/hashicorp/consul/api"
	"hilo/app/service/demo/internal/conf"
kzkzzzz's avatar
kzkzzzz committed
9 10 11 12
)

// ProviderSet is server providers.
var (
kzkzzzz's avatar
kzkzzzz committed
13
	ProviderSet = wire.NewSet(NewHTTPServer, NewGRPCServer, NewConsulRegister)
kzkzzzz's avatar
kzkzzzz committed
14 15
	logHelper   *log.Helper
)
kzkzzzz's avatar
kzkzzzz committed
16 17 18 19 20 21 22 23 24 25 26 27 28

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
}