rename naming

pull/732/head
longXboy 4 years ago
parent 68e857746d
commit f984dc5c6d
  1. 14
      app.go
  2. 10
      options.go
  3. 12
      transport/grpc/client.go

@ -57,9 +57,9 @@ func (a *App) Server() []transport.Server {
return a.opts.servers return a.opts.servers
} }
// Registry returns registry. // Registrar returns registry.
func (a *App) Registry() registry.Registrar { func (a *App) Registrar() registry.Registrar {
return a.opts.registry return a.opts.registrar
} }
// Run executes all OnStart hooks registered with the application's Lifecycle. // Run executes all OnStart hooks registered with the application's Lifecycle.
@ -80,8 +80,8 @@ func (a *App) Run() error {
return srv.Start() return srv.Start()
}) })
} }
if a.opts.registry != nil { if a.opts.registrar != nil {
if err := a.opts.registry.Register(a.opts.ctx, a.instance); err != nil { if err := a.opts.registrar.Register(a.opts.ctx, a.instance); err != nil {
return err return err
} }
} }
@ -105,8 +105,8 @@ func (a *App) Run() error {
// Stop gracefully stops the application. // Stop gracefully stops the application.
func (a *App) Stop() error { func (a *App) Stop() error {
if a.opts.registry != nil { if a.opts.registrar != nil {
if err := a.opts.registry.Deregister(a.opts.ctx, a.instance); err != nil { if err := a.opts.registrar.Deregister(a.opts.ctx, a.instance); err != nil {
return err return err
} }
} }

@ -23,8 +23,8 @@ type options struct {
ctx context.Context ctx context.Context
sigs []os.Signal sigs []os.Signal
logger log.Logger logger log.Logger
registry registry.Registrar registrar registry.Registrar
servers []transport.Server servers []transport.Server
} }
@ -69,9 +69,9 @@ func Logger(logger log.Logger) Option {
return func(o *options) { o.logger = logger } return func(o *options) { o.logger = logger }
} }
// Registry with service registry. // Registrar with service registry.
func Registry(r registry.Registrar) Option { func Registrar(r registry.Registrar) Option {
return func(o *options) { o.registry = r } return func(o *options) { o.registrar = r }
} }
// Server with transport servers. // Server with transport servers.

@ -38,10 +38,10 @@ func WithMiddleware(m middleware.Middleware) ClientOption {
} }
} }
// WithDiscovery with client registry. // WithDiscoverer with client registry.
func WithDiscovery(r registry.Discoverer) ClientOption { func WithDiscoverer(d registry.Discoverer) ClientOption {
return func(o *clientOptions) { return func(o *clientOptions) {
o.discovery = r o.discoverer = d
} }
} }
@ -57,7 +57,7 @@ type clientOptions struct {
endpoint string endpoint string
timeout time.Duration timeout time.Duration
middleware middleware.Middleware middleware middleware.Middleware
discovery registry.Discoverer discoverer registry.Discoverer
grpcOpts []grpc.DialOption grpcOpts []grpc.DialOption
} }
@ -86,8 +86,8 @@ func dial(ctx context.Context, insecure bool, opts ...ClientOption) (*grpc.Clien
grpc.WithTimeout(options.timeout), grpc.WithTimeout(options.timeout),
grpc.WithUnaryInterceptor(UnaryClientInterceptor(options.middleware)), grpc.WithUnaryInterceptor(UnaryClientInterceptor(options.middleware)),
} }
if options.discovery != nil { if options.discoverer != nil {
grpc.WithResolvers(discovery.NewBuilder(options.discovery)) grpc.WithResolvers(discovery.NewBuilder(options.discoverer))
} }
if insecure { if insecure {
grpcOpts = append(grpcOpts, grpc.WithInsecure()) grpcOpts = append(grpcOpts, grpc.WithInsecure())

Loading…
Cancel
Save