|
|
|
@ -28,7 +28,8 @@ type ComponentsKey struct{}
|
|
|
|
|
type Components struct {
|
|
|
|
|
components map[string]Component
|
|
|
|
|
|
|
|
|
|
service micro.Service
|
|
|
|
|
service micro.Service
|
|
|
|
|
flagPrefix string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Context(ctx context.Context) (*Components, error) {
|
|
|
|
@ -61,14 +62,26 @@ func New(components ...Component) *Components {
|
|
|
|
|
return com
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *Components) SetService(service micro.Service) {
|
|
|
|
|
func (c *Components) SetService(service micro.Service) *Components {
|
|
|
|
|
c.service = service
|
|
|
|
|
|
|
|
|
|
return c
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *Components) Service() micro.Service {
|
|
|
|
|
return c.service
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *Components) SetFlagPrefix(flagPrefix string) *Components {
|
|
|
|
|
c.flagPrefix = flagPrefix
|
|
|
|
|
|
|
|
|
|
return c
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *Components) FlagPrefix() string {
|
|
|
|
|
return c.flagPrefix
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *Components) Add(components ...Component) {
|
|
|
|
|
for _, component := range components {
|
|
|
|
|
if component == nil {
|
|
|
|
@ -102,7 +115,7 @@ func (c *Components) Must(name string) Component {
|
|
|
|
|
|
|
|
|
|
func (c *Components) MergeFlags(flags []cli.Flag) []cli.Flag {
|
|
|
|
|
for _, component := range c.components {
|
|
|
|
|
flags = component.MergeFlags(flags)
|
|
|
|
|
flags = component.MergeFlags(c, flags)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return flags
|
|
|
|
|