remove unused options (#767)

pull/769/head
Tony Chen 4 years ago committed by GitHub
parent 21557b38f6
commit ee211bfe1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 30
      app.go
  2. 13
      options.go

@ -9,7 +9,6 @@ import (
"github.com/go-kratos/kratos/v2/log"
"github.com/go-kratos/kratos/v2/registry"
"github.com/go-kratos/kratos/v2/transport"
"github.com/google/uuid"
"golang.org/x/sync/errgroup"
@ -42,26 +41,11 @@ func New(opts ...Option) *App {
opts: options,
ctx: ctx,
cancel: cancel,
instance: serviceInstance(options),
instance: buildInstance(options),
log: log.NewHelper("app", options.logger),
}
}
// Logger returns logger.
func (a *App) Logger() log.Logger {
return a.opts.logger
}
// Server returns transport servers.
func (a *App) Server() []transport.Server {
return a.opts.servers
}
// Registry returns registry.
func (a *App) Registry() registry.Registrar {
return a.opts.registrar
}
// Run executes all OnStart hooks registered with the application's Lifecycle.
func (a *App) Run() error {
a.log.Infow(
@ -80,11 +64,6 @@ func (a *App) Run() error {
return srv.Start()
})
}
for _, fn := range a.opts.before {
if err := fn(); err != nil {
return err
}
}
if a.opts.registrar != nil {
if err := a.opts.registrar.Register(a.opts.ctx, a.instance); err != nil {
return err
@ -118,15 +97,10 @@ func (a *App) Stop() error {
if a.cancel != nil {
a.cancel()
}
for _, fn := range a.opts.after {
if err := fn(); err != nil {
return err
}
}
return nil
}
func serviceInstance(o options) *registry.ServiceInstance {
func buildInstance(o options) *registry.ServiceInstance {
if len(o.endpoints) == 0 {
for _, srv := range o.servers {
if e, err := srv.Endpoint(); err == nil {

@ -27,9 +27,6 @@ type options struct {
registrar registry.Registrar
servers []transport.Server
before []func() error
after []func() error
}
// ID with service id.
@ -81,13 +78,3 @@ func Registrar(r registry.Registrar) Option {
func Server(srv ...transport.Server) Option {
return func(o *options) { o.servers = srv }
}
// Before before service starts.
func Before(fn func() error) Option {
return func(o *options) { o.before = append(o.before, fn) }
}
// After after services stops.
func After(fn func() error) Option {
return func(o *options) { o.after = append(o.after, fn) }
}

Loading…
Cancel
Save