I am beginner for etcd

my purpose is the follow

1.service register itself after service start

2.client find service and invoke service

the follow code show test how to find service and invoke it

func ClientTestService() { cli, err := clientv3.New(clientv3.Config{ Endpoints: []string{endpoint}, DialTimeout: time.Second * 5, }) if err != nil { log.Println("connect etcd err:", err.Error()) return } defer cli.Close() r := &naming.GRPCResolver{Client: cli} b := grpc.RoundRobin(r) conn, err := grpc.Dial(service_name, grpc.WithBalancer(b), grpc.WithInsecure()) if err != nil { log.Println("dial err:", err.Error()) return } defer conn.Close() c := calc.NewCalcClient(conn) req := calc.CalcRequest{IResult: 1, SResult: "req"} resp, err := c.CalcResult(context.Background(), &req) if err != nil { log.Println("calc err:", err) return } log.Println(resp.IResult, resp.SResult) }

console output "calc err: rpc error: code = Unavailable desc = there is no address available" after execute resp, err := c.CalcResult(context.Background(), &req)

it means that resolver can't find the address of service from the service name

i guess there have two possible

1. call service need start etcd "proxy service" or "gateway" first

2. need to get service address from service name by manual

the follow code show register service

func RegisterService(w *sync.WaitGroup) { w.Add(1) defer func() { w.Done() }() cli, err := clientv3.New(clientv3.Config{ Endpoints: []string{endpoint}, DialTimeout: time.Second * 5, }) if err != nil { log.Println("etcd err:", err) return } cli.Delete(cli.Ctx(), service_name) r := &naming.GRPCResolver{Client: cli} for _, addr := range GetLocalAddrs() { service_node := addr + ":" + strconv.Itoa(port) err = r.Update(cli.Ctx(), service_name, gn.Update{Op: gn.Add, Addr: service_node}) log.Println("register node :", service_name, service_node, err) } }

My understanding is that function "ClientTestService" connect etcd server and resolve the service name to service address and invoke service by balance

but when i debug this code and then find it just invoke etcd by balance, is there function in etcd for my need ?