provide basic Context interface and StartFct for components
This commit is contained in:
parent
035090bb04
commit
968bdc925d
5 changed files with 43 additions and 15 deletions
6
common/common.go
Normal file
6
common/common.go
Normal file
|
@ -0,0 +1,6 @@
|
|||
package common
|
||||
|
||||
type Context interface {
|
||||
}
|
||||
|
||||
type StartFct = func(Context)
|
|
@ -1,37 +1,51 @@
|
|||
package config
|
||||
|
||||
import "git.sr.ht/~cco/go-scopes/common"
|
||||
|
||||
type Cfg struct {
|
||||
*BaseConfig
|
||||
*Base
|
||||
ConfigFormat string
|
||||
}
|
||||
|
||||
func Start(ctx common.Context) {
|
||||
}
|
||||
|
||||
// definitions
|
||||
|
||||
type Config interface {
|
||||
Name() string
|
||||
Starter() common.StartFct
|
||||
Children() []Config
|
||||
Add(Config)
|
||||
}
|
||||
|
||||
type BaseConfig struct {
|
||||
type Base struct {
|
||||
name string
|
||||
starter common.StartFct
|
||||
children []Config
|
||||
}
|
||||
|
||||
func (cfg *BaseConfig) Name() string {
|
||||
func (cfg *Base) Name() string {
|
||||
return cfg.name
|
||||
}
|
||||
|
||||
func (cfg *BaseConfig) Children() []Config {
|
||||
func (cfg *Base) Starter() common.StartFct {
|
||||
return cfg.starter
|
||||
}
|
||||
|
||||
func (cfg *Base) Children() []Config {
|
||||
return cfg.children
|
||||
}
|
||||
|
||||
func (cfg *BaseConfig) Add(child Config) {
|
||||
func (cfg *Base) Add(child Config) {
|
||||
cfg.children = append(cfg.children, child)
|
||||
}
|
||||
|
||||
func MakeBase(name string) *BaseConfig {
|
||||
return &BaseConfig{name: name}
|
||||
func MakeBase(name string, starter common.StartFct) *Base {
|
||||
return &Base{
|
||||
name: name,
|
||||
starter: starter,
|
||||
}
|
||||
}
|
||||
|
||||
func Setup(cfg Config) Config {
|
||||
|
|
|
@ -8,10 +8,10 @@ import (
|
|||
func Config() config.Config {
|
||||
b := config.MakeBase
|
||||
cfg := scopes.Cfg{
|
||||
BaseConfig: b("dummy"),
|
||||
AppType: "standard",
|
||||
Base: b("dummy", scopes.Start),
|
||||
AppType: "standard",
|
||||
}
|
||||
cfg.Add(config.Cfg{b("config"), "etc"})
|
||||
cfg.Add(config.Cfg{b("config", config.Start), "etc"})
|
||||
return &cfg
|
||||
}
|
||||
|
||||
|
|
12
scopes.go
12
scopes.go
|
@ -1,12 +1,20 @@
|
|||
package scopes
|
||||
|
||||
import "git.sr.ht/~cco/go-scopes/config"
|
||||
import (
|
||||
"git.sr.ht/~cco/go-scopes/common"
|
||||
"git.sr.ht/~cco/go-scopes/config"
|
||||
)
|
||||
|
||||
type Cfg struct {
|
||||
*config.BaseConfig
|
||||
*config.Base
|
||||
AppType string
|
||||
}
|
||||
|
||||
func Start(ctx common.Context) {
|
||||
}
|
||||
|
||||
// definitions
|
||||
|
||||
func RunApp(cfg config.Config) {
|
||||
_ = cfg
|
||||
}
|
||||
|
|
|
@ -8,10 +8,10 @@ import (
|
|||
func Config() config.Config {
|
||||
b := config.MakeBase
|
||||
cfg := scopes.Cfg{
|
||||
BaseConfig: b("dummy"),
|
||||
AppType: "standard",
|
||||
Base: b("dummy", scopes.Start),
|
||||
AppType: "standard",
|
||||
}
|
||||
cfg.Add(config.Cfg{b("config"), "etc"})
|
||||
cfg.Add(config.Cfg{b("config", config.Start), "etc"})
|
||||
return &cfg
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue