Environment configures providers

This commit is contained in:
Sasha Koshka 2024-12-09 23:27:58 -05:00
parent 433a112875
commit 8084b7749a

View File

@ -23,6 +23,9 @@ type Environment struct {
// functionality to the environment. In order to be used, values in this // functionality to the environment. In order to be used, values in this
// slice must implement one or more of the interfaces in provider.go. // slice must implement one or more of the interfaces in provider.go.
Providers []Provider Providers []Provider
// Conf specifies configuration data. It is used to configure the
// environment, as well as plugins that get loaded.
Conf Meta
documents usync.Locker[map[string] *Document] documents usync.Locker[map[string] *Document]
funcMap template.FuncMap funcMap template.FuncMap
@ -33,12 +36,15 @@ func (this *Environment) Init (ctx context.Context) error {
this.documents = usync.NewLocker(make(map[string] *Document)) this.documents = usync.NewLocker(make(map[string] *Document))
this.funcMap = make(template.FuncMap) this.funcMap = make(template.FuncMap)
for _, provider := range this.Providers { for _, provider := range this.Providers {
provider, ok := provider.(FuncProvider) if provider, ok := provider.(Configurable); ok {
if !ok { continue } provider.Configure(this.Conf)
funcMap := provider.FuncMap() }
if funcMap == nil { continue } if provider, ok := provider.(FuncProvider); ok {
for name, function := range funcMap { funcMap := provider.FuncMap()
this.funcMap[name] = function if funcMap == nil { continue }
for name, function := range funcMap {
this.funcMap[name] = function
}
} }
} }
return ctx.Err() return ctx.Err()