internal/component: Update documentation and linting
This commit is contained in:
parent
84974dd712
commit
a63e656f69
2 changed files with 64 additions and 49 deletions
|
|
@ -32,6 +32,7 @@ type ComponentBase struct {
|
||||||
Core // the core of the associated distillery
|
Core // the core of the associated distillery
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//lint:ignore U1000 used to implement the private methods of [Component]
|
||||||
func (cb *ComponentBase) getBase() *ComponentBase {
|
func (cb *ComponentBase) getBase() *ComponentBase {
|
||||||
return cb
|
return cb
|
||||||
}
|
}
|
||||||
|
|
@ -42,7 +43,8 @@ func (cb *ComponentBase) getBase() *ComponentBase {
|
||||||
//
|
//
|
||||||
// dis is the distillery to initialize components for
|
// dis is the distillery to initialize components for
|
||||||
// field is a pointer to the appropriate struct field within the distillery components
|
// field is a pointer to the appropriate struct field within the distillery components
|
||||||
// init is called with a new non-nil component to initialize it. It may be nil, to indicate no initialization is required.
|
// init is called with a new non-nil component to initialize it.
|
||||||
|
// It may be nil, to indicate no additional initialization is required.
|
||||||
//
|
//
|
||||||
// makeComponent returns the new or existing component instance
|
// makeComponent returns the new or existing component instance
|
||||||
func Initialize[C Component](core Core, field *lazy.Lazy[C], init func(C)) C {
|
func Initialize[C Component](core Core, field *lazy.Lazy[C], init func(C)) C {
|
||||||
|
|
|
||||||
|
|
@ -31,60 +31,18 @@ type components struct {
|
||||||
instances lazy.Lazy[*instances.Instances]
|
instances lazy.Lazy[*instances.Instances]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dis *Distillery) Components() []component.Component {
|
//
|
||||||
return []component.Component{
|
// Individual Components
|
||||||
dis.Web(),
|
//
|
||||||
dis.Control(),
|
|
||||||
dis.SSH(),
|
|
||||||
dis.Triplestore(),
|
|
||||||
dis.SQL(),
|
|
||||||
dis.Instances(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Backupable returns all the components that can be backuped up.
|
|
||||||
func (dis *Distillery) Backupable() []component.Backupable {
|
|
||||||
return getComponents[component.Backupable](dis)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Installables returns all components that can be installed
|
|
||||||
func (dis *Distillery) Installables() []component.Installable {
|
|
||||||
return getComponents[component.Installable](dis)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Installables returns all components that can be installed
|
|
||||||
func (dis *Distillery) Updateable() []component.Updatable {
|
|
||||||
return getComponents[component.Updatable](dis)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Provisionable returns all components which can be provisioned
|
|
||||||
func (dis *Distillery) Provisionable() []component.Provisionable {
|
|
||||||
return getComponents[component.Provisionable](dis)
|
|
||||||
}
|
|
||||||
|
|
||||||
func getComponents[C component.Component](dis *Distillery) (result []C) {
|
|
||||||
all := dis.Components()
|
|
||||||
|
|
||||||
result = make([]C, 0, len(all))
|
|
||||||
for _, c := range all {
|
|
||||||
sc, ok := c.(C)
|
|
||||||
if !ok {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
result = append(result, sc)
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dis *Distillery) Web() *web.Web {
|
func (dis *Distillery) Web() *web.Web {
|
||||||
return component.Initialize(dis.Core, &dis.components.web, nil)
|
return component.Initialize(dis.Core, &dis.components.web, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Distillery) Control() *control.Control {
|
func (d *Distillery) Control() *control.Control {
|
||||||
return component.Initialize(d.Core, &d.components.control, func(ddis *control.Control) {
|
return component.Initialize(d.Core, &d.components.control, func(control *control.Control) {
|
||||||
ddis.ResolverFile = core.PrefixConfig
|
control.ResolverFile = core.PrefixConfig
|
||||||
ddis.Instances = d.Instances()
|
control.Instances = d.Instances()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -114,3 +72,58 @@ func (dis *Distillery) Instances() *instances.Instances {
|
||||||
instances.TS = dis.Triplestore()
|
instances.TS = dis.Triplestore()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// ALL COMPONENTS
|
||||||
|
//
|
||||||
|
|
||||||
|
func (dis *Distillery) Components() []component.Component {
|
||||||
|
return []component.Component{
|
||||||
|
dis.Web(),
|
||||||
|
dis.Control(),
|
||||||
|
dis.SSH(),
|
||||||
|
dis.Triplestore(),
|
||||||
|
dis.SQL(),
|
||||||
|
dis.Instances(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// COMPONENT SUBTYPE GETTERS
|
||||||
|
//
|
||||||
|
|
||||||
|
// Backupable returns all the components that can be backuped up.
|
||||||
|
func (dis *Distillery) Backupable() []component.Backupable {
|
||||||
|
return getComponentSubtype[component.Backupable](dis)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Installables returns all components that can be installed
|
||||||
|
func (dis *Distillery) Installables() []component.Installable {
|
||||||
|
return getComponentSubtype[component.Installable](dis)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Installables returns all components that can be installed
|
||||||
|
func (dis *Distillery) Updateable() []component.Updatable {
|
||||||
|
return getComponentSubtype[component.Updatable](dis)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Provisionable returns all components which can be provisioned
|
||||||
|
func (dis *Distillery) Provisionable() []component.Provisionable {
|
||||||
|
return getComponentSubtype[component.Provisionable](dis)
|
||||||
|
}
|
||||||
|
|
||||||
|
// getComponentSubtype gets all components of type T
|
||||||
|
func getComponentSubtype[T component.Component](dis *Distillery) (components []T) {
|
||||||
|
all := dis.Components()
|
||||||
|
|
||||||
|
components = make([]T, 0, len(all))
|
||||||
|
for _, c := range all {
|
||||||
|
sc, ok := c.(T)
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
components = append(components, sc)
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue