component: Automatically determine names

This commit is contained in:
Tom Wiesing 2022-10-17 20:39:53 +02:00
parent 10df1c3243
commit e320bb37bb
No known key found for this signature in database
31 changed files with 84 additions and 113 deletions

View file

@ -0,0 +1,36 @@
package component
import (
"reflect"
"strings"
"github.com/FAU-CDI/wisski-distillery/internal/config"
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
)
// ComponentBase is embedded into every Component
type ComponentBase struct {
name string // name is the name of this component
Still // the underlying still of the distillery
}
//lint:ignore U1000 used to implement the private methods of [Component]
func (cb *ComponentBase) getComponentBase() *ComponentBase {
return cb
}
func (cb ComponentBase) Name() string {
return cb.name
}
// nameOf returns the name of the given component
func nameOf(component Component) string {
return strings.ToLower(reflect.TypeOf(component).Elem().Name())
}
// Still represents the central part of a distillery.
// It is used inside the main distillery struct, as well as every component via [ComponentBase].
type Still struct {
Environment environment.Environment // environment to use for reading / writing to and from the distillery
Config *config.Config // the configuration of the distillery
}