it compiles

This commit is contained in:
Daniel Ponte 2022-12-20 13:31:31 -05:00
parent 0378151b9f
commit 0da222577b
5 changed files with 28 additions and 43 deletions

View file

@ -3,7 +3,6 @@ package blas
import ( import (
"context" "context"
"dynatron.me/x/blasphem/pkg/auth" "dynatron.me/x/blasphem/pkg/auth"
"dynatron.me/x/blasphem/pkg/blas/core"
"dynatron.me/x/blasphem/pkg/bus" "dynatron.me/x/blasphem/pkg/bus"
"dynatron.me/x/blasphem/pkg/config" "dynatron.me/x/blasphem/pkg/config"
"dynatron.me/x/blasphem/pkg/storage" "dynatron.me/x/blasphem/pkg/storage"
@ -18,8 +17,6 @@ type Core interface {
Versioner Versioner
} }
var _ Core = (*core.Blas)(nil)
type Shutdowner interface { type Shutdowner interface {
ShutdownBlas(context.Context) error ShutdownBlas(context.Context) error
} }

26
pkg/blas/components.go Normal file
View file

@ -0,0 +1,26 @@
package blas
import (
"fmt"
)
type (
Setup func(Core) (Component, error)
Key string
Component interface {
Shutdown()
}
)
var Registry = make(map[Key]Setup)
func Register(key Key, c Setup) {
_, already := Registry[key]
if already {
panic(fmt.Sprintf("component %s already exists", key))
}
Registry[key] = c
}

View file

@ -1,13 +0,0 @@
package component
import (
"dynatron.me/x/blasphem/pkg/blas"
)
type (
Setup func(blas.Core) (Instance, error)
Instance interface {
Shutdown()
}
)

View file

@ -1,24 +0,0 @@
package reg
import (
"fmt"
"dynatron.me/x/blasphem/pkg/component"
)
type (
Key string
)
type Instance = component.Instance
var Registry = make(map[Key]component.Setup)
func Register(key Key, c component.Setup) {
_, already := Registry[key]
if already {
panic(fmt.Sprintf("component %s already exists", key))
}
Registry[key] = c
}

View file

@ -8,7 +8,6 @@ import (
"sync" "sync"
"dynatron.me/x/blasphem/pkg/blas" "dynatron.me/x/blasphem/pkg/blas"
"dynatron.me/x/blasphem/pkg/component/reg"
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
) )
@ -50,7 +49,7 @@ func (fe *Frontend) AliasHandler(toFile string) echo.HandlerFunc {
func (*Frontend) Shutdown() {} func (*Frontend) Shutdown() {}
func Setup(_ blas.Core) (reg.Instance, error) { func Setup(_ blas.Core) (blas.Component, error) {
fe := &Frontend{} fe := &Frontend{}
var err error var err error
@ -65,5 +64,5 @@ func Setup(_ blas.Core) (reg.Instance, error) {
} }
func init() { func init() {
reg.Register(FrontendKey, Setup) blas.Register(FrontendKey, Setup)
} }