From 968bdc925dbae165e7e09cd0acc833bb3e8d46aa Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Thu, 1 Jun 2023 17:13:17 +0200 Subject: [PATCH] provide basic Context interface and StartFct for components --- common/common.go | 6 ++++++ config/config.go | 28 +++++++++++++++++++++------- examples/demo/etc/etc.go | 6 +++--- scopes.go | 12 ++++++++++-- tests/etc/etc.go | 6 +++--- 5 files changed, 43 insertions(+), 15 deletions(-) create mode 100644 common/common.go diff --git a/common/common.go b/common/common.go new file mode 100644 index 0000000..2d5eed1 --- /dev/null +++ b/common/common.go @@ -0,0 +1,6 @@ +package common + +type Context interface { +} + +type StartFct = func(Context) diff --git a/config/config.go b/config/config.go index c0915ea..d07108a 100644 --- a/config/config.go +++ b/config/config.go @@ -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 { diff --git a/examples/demo/etc/etc.go b/examples/demo/etc/etc.go index 06caba4..030d4b0 100644 --- a/examples/demo/etc/etc.go +++ b/examples/demo/etc/etc.go @@ -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 } diff --git a/scopes.go b/scopes.go index 43f0b94..14b21f7 100644 --- a/scopes.go +++ b/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 } diff --git a/tests/etc/etc.go b/tests/etc/etc.go index 0f4795b..957f8e5 100644 --- a/tests/etc/etc.go +++ b/tests/etc/etc.go @@ -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 }