provide basic Context interface and StartFct for components

This commit is contained in:
Helmut Merz 2023-06-01 17:13:17 +02:00
parent 035090bb04
commit 968bdc925d
5 changed files with 43 additions and 15 deletions

6
common/common.go Normal file
View file

@ -0,0 +1,6 @@
package common
type Context interface {
}
type StartFct = func(Context)

View file

@ -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 {

View file

@ -8,10 +8,10 @@ import (
func Config() config.Config {
b := config.MakeBase
cfg := scopes.Cfg{
BaseConfig: b("dummy"),
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
}

View file

@ -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
}

View file

@ -8,10 +8,10 @@ import (
func Config() config.Config {
b := config.MakeBase
cfg := scopes.Cfg{
BaseConfig: b("dummy"),
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
}