72 lines
1 KiB
Go
72 lines
1 KiB
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
|
|
"git.sr.ht/~cco/go-scopes/common"
|
|
)
|
|
|
|
type Cfg struct {
|
|
*Base
|
|
ConfigFormat string
|
|
}
|
|
|
|
func Start(ctx common.Context) {
|
|
}
|
|
|
|
// definitions
|
|
|
|
type Config interface {
|
|
Name() string
|
|
Starter() common.StartFct
|
|
Children() []Config
|
|
Add(Config)
|
|
}
|
|
|
|
type Base struct {
|
|
name string
|
|
starter common.StartFct
|
|
children []Config
|
|
}
|
|
|
|
func (cfg *Base) Name() string {
|
|
return cfg.name
|
|
}
|
|
|
|
func (cfg *Base) Starter() common.StartFct {
|
|
return cfg.starter
|
|
}
|
|
|
|
func (cfg *Base) Children() []Config {
|
|
return cfg.children
|
|
}
|
|
|
|
func (cfg *Base) Add(child Config) {
|
|
cfg.children = append(cfg.children, child)
|
|
}
|
|
|
|
func MakeBase(name string, starter common.StartFct) *Base {
|
|
return &Base{
|
|
name: name,
|
|
starter: starter,
|
|
}
|
|
}
|
|
|
|
func Setup(cfg Config) Config {
|
|
return cfg
|
|
}
|
|
|
|
// overridable settings
|
|
|
|
type Settings map[string]string
|
|
|
|
func (s Settings) Get(key, def string) string {
|
|
if v, ok := os.LookupEnv("SCOPES_" + strings.ToUpper(key)); ok {
|
|
return v
|
|
}
|
|
if v, ok := s[key]; ok {
|
|
return v
|
|
}
|
|
return def
|
|
}
|