ace

module
v0.2.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 20, 2024 License: MIT

README

Ace

Using etcd discovery with go-grpc

B 站视频: gRPC + etcd 服务注册与发现

Getting Started

addsvc.go

func main() {
	svc := ace.NewService(
		ace.Name("hello"),
		ace.EtcdUrls([]string{"localhost:2379"}),
		ace.RegisterServiceFn(func(s *server.Server) {
			pb.RegisterAddServer(s, &service.AddSvc{})
			pb.RegisterHelloWorldServiceServer(s, &service.HelloSvc{})
		}),
	)

	svc.Run()
}

addcli.go

func main() {
	ctx := context.Background()
	conn, err := ace.Dial(ctx, "hello", []string{"localhost:2379"})
	if err != nil {
		panic(err)
	}
	defer conn.Close()

	var a, b int64 = 2, 3
	addClient := pb.NewAddClient(conn)
	sumReply, err := addClient.Sum(ctx, &pb.SumRequest{A: a, B: b})
	if err != nil {
		fmt.Println("err", err)
		return
	}
	fmt.Printf("%d + %d = %d\n", a, b, sumReply.V)
}

etcd 与 gRPC 版本兼容问题

go.etcd.io/etcd/client/v3@v3.5.9/naming/resolver/resolver.go:22:11: cannot use target.Endpoint (value of type func() string) as type string in struct literal

replace google.golang.org/grpc => google.golang.org/grpc v1.52.3

references

  1. gRPC naming and discovery
  2. go-kit
  3. go-micro

Directories

Path Synopsis
cmd
pub
internal
pkg
hls
playlist
Package playlist contains a M3U8 playlist decoder and encoder.
Package playlist contains a M3U8 playlist decoder and encoder.
playlist/primitives
Package primitives contains playlist primitives.
Package primitives contains playlist primitives.
ws

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL