From 52d825597480ba81aa3052b0d60a19794c1ca2e1 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sun, 28 Mar 2021 23:42:02 +0300 Subject: [PATCH] service init with own context Signed-off-by: Vasiliy Tolstov --- go.sum | 1 + service.go | 16 ++++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/go.sum b/go.sum index dfa6b9c8..5033b2e5 100644 --- a/go.sum +++ b/go.sum @@ -10,6 +10,7 @@ github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaR github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ= github.com/silas/dag v0.0.0-20210121180416-41cf55125c34 h1:vBfVmA5mZhsQa2jr1FOL9nfA37N/jnbBmi5XUfviVTI= github.com/silas/dag v0.0.0-20210121180416-41cf55125c34/go.mod h1:7RTUFBdIRC9nZ7/3RyRNH1bdqIShrDejd1YbLwgPS+I= +golang.org/x/net v0.0.0-20210326220855-61e056675ecf h1:WUcCxqQqDT0aXO4VnQbfMvp4zh7m1Gb2clVuHUAGGRE= golang.org/x/net v0.0.0-20210326220855-61e056675ecf/go.mod h1:uSPa2vr4CLtc/ILN5odXGNXS6mhrKVzTaCXzk9m6W3k= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210324051608-47abb6519492/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/service.go b/service.go index 04193f33..b06aa589 100644 --- a/service.go +++ b/service.go @@ -103,48 +103,48 @@ func (s *service) Init(opts ...Option) error { // skip config as the struct not passed continue } - if err = cfg.Init(config.Context(s.opts.Context)); err != nil { + if err = cfg.Init(config.Context(cfg.Options().Context)); err != nil { return err } - if err = cfg.Load(s.opts.Context); err != nil { + if err = cfg.Load(cfg.Options().Context); err != nil { return err } } for _, log := range s.opts.Loggers { - if err = log.Init(logger.WithContext(s.opts.Context)); err != nil { + if err = log.Init(logger.WithContext(log.Options().Context)); err != nil { return err } } for _, reg := range s.opts.Registers { - if err = reg.Init(register.Context(s.opts.Context)); err != nil { + if err = reg.Init(register.Context(reg.Options().Context)); err != nil { return err } } for _, brk := range s.opts.Brokers { - if err = brk.Init(broker.Context(s.opts.Context)); err != nil { + if err = brk.Init(broker.Context(brk.Options().Context)); err != nil { return err } } for _, str := range s.opts.Stores { - if err = str.Init(store.Context(s.opts.Context)); err != nil { + if err = str.Init(store.Context(str.Options().Context)); err != nil { return err } } for _, srv := range s.opts.Servers { - if err = srv.Init(server.Context(s.opts.Context)); err != nil { + if err = srv.Init(server.Context(srv.Options().Context)); err != nil { return err } } for _, cli := range s.opts.Clients { - if err = cli.Init(client.Context(s.opts.Context)); err != nil { + if err = cli.Init(client.Context(cli.Options().Context)); err != nil { return err } }