internal: Annotate all components with groups

This commit ensures that the compiler has to check every component
against the groups they implement by explicitly annotating the
appropriate interfaces.
This commit is contained in:
Tom Wiesing 2022-11-30 11:08:46 +01:00
parent 3455f491ca
commit 890022ae64
No known key found for this signature in database
29 changed files with 163 additions and 33 deletions

View file

@ -13,6 +13,12 @@ import (
func (dis *Distillery) init() {
dis.poolInit.Do(func() {
dis.pool.Init = component.Init
lazy.RegisterPoolGroup[component.Backupable](&dis.pool)
lazy.RegisterPoolGroup[component.Snapshotable](&dis.pool)
lazy.RegisterPoolGroup[component.DistilleryFetcher](&dis.pool)
lazy.RegisterPoolGroup[component.Installable](&dis.pool)
lazy.RegisterPoolGroup[component.Provisionable](&dis.pool)
lazy.RegisterPoolGroup[component.Servable](&dis.pool)
})
}

View file

@ -16,6 +16,10 @@ type Control struct {
Servables []component.Servable
}
var (
_ component.Installable = (*Control)(nil)
)
func (control Control) Path() string {
return filepath.Join(control.Still.Config.DeployRoot, "core", "dis")
}

View file

@ -24,6 +24,10 @@ type Home struct {
homeBytes lazy.Lazy[[]byte]
}
var (
_ component.Servable = (*Home)(nil)
)
func (*Home) Routes() []string { return []string{"/"} }
func (home *Home) Handler(ctx context.Context, route string, io stream.IOStream) (http.Handler, error) {

View file

@ -26,6 +26,11 @@ type Info struct {
SnapshotsLog *logger.Logger
}
var (
_ component.DistilleryFetcher = (*Info)(nil)
_ component.Servable = (*Info)(nil)
)
func (*Info) Routes() []string { return []string{"/dis/"} }
func (info *Info) Handler(ctx context.Context, route string, io stream.IOStream) (handler http.Handler, err error) {

View file

@ -15,6 +15,10 @@ type Static struct {
component.Base
}
var (
_ component.Servable = (*Static)(nil)
)
func (*Static) Routes() []string { return []string{"/static/"} }
//go:embed dist

View file

@ -13,6 +13,10 @@ type Bookkeeping struct {
component.Base
}
var (
_ component.Snapshotable = (*Bookkeeping)(nil)
)
// SnapshotNeedsRunning returns if this Snapshotable requires a running instance.
func (Bookkeeping) SnapshotNeedsRunning() bool { return false }

View file

@ -12,6 +12,10 @@ type Config struct {
component.Base
}
var (
_ = (component.Backupable)((*Config)(nil))
)
func (*Config) BackupName() string {
return "config"
}

View file

@ -10,6 +10,10 @@ type Filesystem struct {
component.Base
}
var (
_ component.Snapshotable = (*Filesystem)(nil)
)
// SnapshotNeedsRunning returns if this Snapshotable requires a running instance.
func (Filesystem) SnapshotNeedsRunning() bool { return false }

View file

@ -14,6 +14,10 @@ type Pathbuilders struct {
Instances *instances.Instances
}
var (
_ component.Snapshotable = (*Pathbuilders)(nil)
)
func (Pathbuilders) SnapshotNeedsRunning() bool { return true }
func (Pathbuilders) SnapshotName() string { return "pathbuilders" }

View file

@ -26,6 +26,10 @@ type Resolver struct {
handler lazy.Lazy[wdresolve.ResolveHandler] // handler
}
var (
_ component.Servable = (*Resolver)(nil)
)
func (resolver *Resolver) Routes() []string { return []string{"/go/", "/wisski/get/"} }
func (resolver *Resolver) Handler(ctx context.Context, route string, io stream.IOStream) (http.Handler, error) {

View file

@ -17,6 +17,10 @@ type Solr struct {
PollInterval time.Duration // duration to wait for during wait
}
var (
_ component.Installable = (*Solr)(nil)
)
func (s *Solr) Path() string {
return filepath.Join(s.Still.Config.DeployRoot, "core", "solr")
}

View file

@ -20,6 +20,12 @@ type SQL struct {
lazyNetwork lazy.Lazy[string]
}
var (
_ component.Backupable = (*SQL)(nil)
_ component.Snapshotable = (*SQL)(nil)
_ component.Installable = (*SQL)(nil)
)
func (sql *SQL) Path() string {
return filepath.Join(sql.Still.Config.DeployRoot, "core", "sql")
}

View file

@ -14,6 +14,10 @@ type SSH2 struct {
Instances *instances.Instances
}
var (
_ component.Installable = (*SSH2)(nil)
)
// GlobalKeys returns the global authorized keys
func (s *SSH2) GlobalKeys() ([]ssh.PublicKey, error) {
file, err := s.Environment.Open(s.Config.GlobalAuthorizedKeysFile)

View file

@ -17,6 +17,12 @@ type Triplestore struct {
PollInterval time.Duration // duration to wait for during wait
}
var (
_ component.Backupable = (*Triplestore)(nil)
_ component.Snapshotable = (*Triplestore)(nil)
_ component.Installable = (*Triplestore)(nil)
)
func (ts *Triplestore) Path() string {
return filepath.Join(ts.Still.Config.DeployRoot, "core", "triplestore")
}

View file

@ -15,6 +15,10 @@ type Web struct {
component.Base
}
var (
_ component.Installable = (*Web)(nil)
)
func (web *Web) Path() string {
return filepath.Join(web.Still.Config.DeployRoot, "core", "web")
}