load config on service init
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
		
							
								
								
									
										32
									
								
								service.go
									
									
									
									
									
								
							
							
						
						
									
										32
									
								
								service.go
									
									
									
									
									
								
							| @@ -40,6 +40,30 @@ func (s *service) Init(opts ...Option) error { | |||||||
| 		o(&s.opts) | 		o(&s.opts) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	for _, cfg := range s.opts.Configs { | ||||||
|  |  | ||||||
|  | 		if err := cfg.Init(config.Context(s.opts.Context)); err != nil { | ||||||
|  | 			return err | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		for _, fn := range cfg.Options().BeforeLoad { | ||||||
|  | 			if err := fn(s.opts.Context, cfg); err != nil { | ||||||
|  | 				return err | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		if err := cfg.Load(s.opts.Context); err != nil { | ||||||
|  | 			return err | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		for _, fn := range cfg.Options().AfterLoad { | ||||||
|  | 			if err := fn(s.opts.Context, cfg); err != nil { | ||||||
|  | 				return err | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	if s.opts.Logger != nil { | 	if s.opts.Logger != nil { | ||||||
| 		if err := s.opts.Logger.Init( | 		if err := s.opts.Logger.Init( | ||||||
| 			logger.WithContext(s.opts.Context), | 			logger.WithContext(s.opts.Context), | ||||||
| @@ -48,14 +72,6 @@ func (s *service) Init(opts ...Option) error { | |||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if s.opts.Configs != nil { |  | ||||||
| 		for _, c := range s.opts.Configs { |  | ||||||
| 			if err := c.Init(config.Context(s.opts.Context)); err != nil { |  | ||||||
| 				return err |  | ||||||
| 			} |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	if s.opts.Registry != nil { | 	if s.opts.Registry != nil { | ||||||
| 		if err := s.opts.Registry.Init( | 		if err := s.opts.Registry.Init( | ||||||
| 			registry.Context(s.opts.Context), | 			registry.Context(s.opts.Context), | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user