Skip to main content
Version: 2.8.x(Latest)

Add the configuration file:

app/word/manifest/config/etcd.yaml

etcd:  
address: "srv.com:2379"

Add the registration logic to the entry file:

app/word/main.go

package main  

import (
_ "github.com/gogf/gf/contrib/drivers/mysql/v2"

"github.com/gogf/gf/contrib/registry/etcd/v2"
"github.com/gogf/gf/contrib/rpc/grpcx/v2"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gctx"

"proxima/app/word/internal/cmd"
)

func main() {
var ctx = gctx.New()
conf, err := g.Cfg("etcd").Get(ctx, "etcd.address")
if err != nil {
panic(err)
}

var address = conf.String()
grpcx.Resolver.Register(etcd.New(address))

cmd.Main.Run(ctx)
}

Restart the project, enter the etcd container again, and execute the following command to verify:

$ etcdctl get "" --prefix --keys-only
/service/default/default/user/latest/{IP}:32001
/service/default/default/word/latest/{IP}:32002

As we can see, both of our microservices have been successfully registered. Next, we can run the gateway to start calling these services.