package server import ( "fmt" "github.com/asim/go-micro/plugins/registry/consul/v4" "github.com/asim/go-micro/plugins/server/grpc/v4" "go-micro.dev/v4" "go-micro.dev/v4/registry" "go-micro.dev/v4/server" "gomicro-base/api/demo" "gomicro-base/service/demo/internal/conf" "gomicro-base/service/demo/internal/service" "time" ) func NewMicroServer(conf *conf.Config, svc *service.DemoService) micro.Service { reg := consul.NewRegistry(registry.Addrs(conf.Server.ConsulServer...)) //reg := etcd.NewRegistry(registry.Addrs(conf.Server.EtcdServer...)) opt := []micro.Option{ micro.Server(grpc.NewServer()), micro.Name(conf.Server.Name), micro.Address(conf.Server.Grpc.Addr), micro.Registry(reg), micro.RegisterTTL(time.Second * 30), micro.RegisterInterval(time.Second * 10), } s := micro.NewService(opt...) s.Server().Init(server.Wait(nil)) //reflection.Register() s.Init() err := demo.RegisterDemoHandler(s.Server(), &handler{svc: svc}) if err != nil { fmt.Println(err) } return s }