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.
29 lines
634 B
29 lines
634 B
package livezk |
|
|
|
import ( |
|
"context" |
|
"fmt" |
|
"net" |
|
|
|
"go-common/library/naming" |
|
lz "go-common/library/naming/livezk" |
|
"go-common/library/net/ip" |
|
) |
|
|
|
// Register self grpc service to live zookeeper |
|
func Register(config *lz.Zookeeper, addr string, discoveryID string) (context.CancelFunc, error) { |
|
_, port, err := net.SplitHostPort(addr) |
|
if err != nil { |
|
return nil, err |
|
} |
|
z, err := lz.New(config) |
|
if err != nil { |
|
return nil, err |
|
} |
|
internalIP := ip.InternalIP() |
|
ins := &naming.Instance{ |
|
AppID: discoveryID, |
|
Addrs: []string{fmt.Sprintf("grpc://%s:%s", internalIP, port)}, |
|
} |
|
return z.Register(context.Background(), ins) |
|
}
|
|
|