You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
641 B
Go
30 lines
641 B
Go
4 years ago
|
package internal
|
||
4 years ago
|
|
||
|
import "zero/core/discov"
|
||
|
|
||
|
func NewRpcPubServer(etcdEndpoints []string, etcdKey, listenOn string, opts ...ServerOption) (Server, error) {
|
||
|
registerEtcd := func() error {
|
||
|
pubClient := discov.NewPublisher(etcdEndpoints, etcdKey, listenOn)
|
||
|
return pubClient.KeepAlive()
|
||
|
}
|
||
|
server := keepAliveServer{
|
||
|
registerEtcd: registerEtcd,
|
||
|
Server: NewRpcServer(listenOn, opts...),
|
||
|
}
|
||
|
|
||
|
return server, nil
|
||
|
}
|
||
|
|
||
|
type keepAliveServer struct {
|
||
|
registerEtcd func() error
|
||
|
Server
|
||
|
}
|
||
|
|
||
|
func (ags keepAliveServer) Start(fn RegisterFn) error {
|
||
|
if err := ags.registerEtcd(); err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
return ags.Server.Start(fn)
|
||
|
}
|