You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
690 B
33 lines
690 B
package discovery |
|
|
|
import ( |
|
"context" |
|
"fmt" |
|
clientv3 "go.etcd.io/etcd/client/v3" |
|
"go.etcd.io/etcd/client/v3/naming/endpoints" |
|
) |
|
|
|
func EtcdDialUrl(serviceName string) string { |
|
return fmt.Sprintf("etcd:///%s", serviceName) |
|
} |
|
|
|
func EtcdRegistry(client *clientv3.Client, serviceName, addr string, attrs map[string]string) (err error) { |
|
em, err := endpoints.NewManager(client, "Hello") |
|
if err != nil { |
|
return |
|
} |
|
ip, port, err := RegisterIpPort(addr) |
|
if err != nil { |
|
return |
|
} |
|
fmt.Println() |
|
|
|
err = em.AddEndpoint(context.Background(), |
|
fmt.Sprintf("%s/%s", serviceName, ip), |
|
endpoints.Endpoint{ |
|
Addr: fmt.Sprintf("%s:%d", ip, port), |
|
Metadata: attrs, |
|
}, |
|
) |
|
return |
|
}
|
|
|