rpcpubserver.go 664 B

1234567891011121314151617181920212223242526272829
  1. package internal
  2. import "github.com/tal-tech/go-zero/core/discov"
  3. func NewRpcPubServer(etcdEndpoints []string, etcdKey, listenOn string, opts ...ServerOption) (Server, error) {
  4. registerEtcd := func() error {
  5. pubClient := discov.NewPublisher(etcdEndpoints, etcdKey, listenOn)
  6. return pubClient.KeepAlive()
  7. }
  8. server := keepAliveServer{
  9. registerEtcd: registerEtcd,
  10. Server: NewRpcServer(listenOn, opts...),
  11. }
  12. return server, nil
  13. }
  14. type keepAliveServer struct {
  15. registerEtcd func() error
  16. Server
  17. }
  18. func (ags keepAliveServer) Start(fn RegisterFn) error {
  19. if err := ags.registerEtcd(); err != nil {
  20. return err
  21. }
  22. return ags.Server.Start(fn)
  23. }