From ee211bfe1b82653e086942fc25bdcef8754b20c0 Mon Sep 17 00:00:00 2001 From: Tony Chen Date: Sun, 14 Mar 2021 16:04:37 +0800 Subject: [PATCH] remove unused options (#767) --- app.go | 30 ++---------------------------- options.go | 13 ------------- 2 files changed, 2 insertions(+), 41 deletions(-) diff --git a/app.go b/app.go index a01e98493..1b5c42d8a 100644 --- a/app.go +++ b/app.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 { diff --git a/options.go b/options.go index 3c615ed9a..cecb4eaa0 100644 --- a/options.go +++ b/options.go @@ -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) } -}