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
|
package config
|
||||||
|
|
||||||
|
import "git.sr.ht/~cco/go-scopes/common"
|
||||||
|
|
||||||
type Cfg struct {
|
type Cfg struct {
|
||||||
*BaseConfig
|
*Base
|
||||||
ConfigFormat string
|
ConfigFormat string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Start(ctx common.Context) {
|
||||||
|
}
|
||||||
|
|
||||||
// definitions
|
// definitions
|
||||||
|
|
||||||
type Config interface {
|
type Config interface {
|
||||||
Name() string
|
Name() string
|
||||||
|
Starter() common.StartFct
|
||||||
Children() []Config
|
Children() []Config
|
||||||
Add(Config)
|
Add(Config)
|
||||||
}
|
}
|
||||||
|
|
||||||
type BaseConfig struct {
|
type Base struct {
|
||||||
name string
|
name string
|
||||||
|
starter common.StartFct
|
||||||
children []Config
|
children []Config
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cfg *BaseConfig) Name() string {
|
func (cfg *Base) Name() string {
|
||||||
return cfg.name
|
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
|
return cfg.children
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cfg *BaseConfig) Add(child Config) {
|
func (cfg *Base) Add(child Config) {
|
||||||
cfg.children = append(cfg.children, child)
|
cfg.children = append(cfg.children, child)
|
||||||
}
|
}
|
||||||
|
|
||||||
func MakeBase(name string) *BaseConfig {
|
func MakeBase(name string, starter common.StartFct) *Base {
|
||||||
return &BaseConfig{name: name}
|
return &Base{
|
||||||
|
name: name,
|
||||||
|
starter: starter,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Setup(cfg Config) Config {
|
func Setup(cfg Config) Config {
|
||||||
|
|
|
@ -8,10 +8,10 @@ import (
|
||||||
func Config() config.Config {
|
func Config() config.Config {
|
||||||
b := config.MakeBase
|
b := config.MakeBase
|
||||||
cfg := scopes.Cfg{
|
cfg := scopes.Cfg{
|
||||||
BaseConfig: b("dummy"),
|
Base: b("dummy", scopes.Start),
|
||||||
AppType: "standard",
|
AppType: "standard",
|
||||||
}
|
}
|
||||||
cfg.Add(config.Cfg{b("config"), "etc"})
|
cfg.Add(config.Cfg{b("config", config.Start), "etc"})
|
||||||
return &cfg
|
return &cfg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
12
scopes.go
12
scopes.go
|
@ -1,12 +1,20 @@
|
||||||
package scopes
|
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 {
|
type Cfg struct {
|
||||||
*config.BaseConfig
|
*config.Base
|
||||||
AppType string
|
AppType string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Start(ctx common.Context) {
|
||||||
|
}
|
||||||
|
|
||||||
|
// definitions
|
||||||
|
|
||||||
func RunApp(cfg config.Config) {
|
func RunApp(cfg config.Config) {
|
||||||
_ = cfg
|
_ = cfg
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,10 +8,10 @@ import (
|
||||||
func Config() config.Config {
|
func Config() config.Config {
|
||||||
b := config.MakeBase
|
b := config.MakeBase
|
||||||
cfg := scopes.Cfg{
|
cfg := scopes.Cfg{
|
||||||
BaseConfig: b("dummy"),
|
Base: b("dummy", scopes.Start),
|
||||||
AppType: "standard",
|
AppType: "standard",
|
||||||
}
|
}
|
||||||
cfg.Add(config.Cfg{b("config"), "etc"})
|
cfg.Add(config.Cfg{b("config", config.Start), "etc"})
|
||||||
return &cfg
|
return &cfg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue