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
// slice must implement one or more of the interfaces in provider.go.
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]
funcMap template.FuncMap
@ -33,12 +36,15 @@ func (this *Environment) Init (ctx context.Context) error {
this.documents = usync.NewLocker(make(map[string] *Document))
this.funcMap = make(template.FuncMap)
for _, provider := range this.Providers {
provider, ok := provider.(FuncProvider)
if !ok { continue }
funcMap := provider.FuncMap()
if funcMap == nil { continue }
for name, function := range funcMap {
this.funcMap[name] = function
if provider, ok := provider.(Configurable); ok {
provider.Configure(this.Conf)
}
if provider, ok := provider.(FuncProvider); ok {
funcMap := provider.FuncMap()
if funcMap == nil { continue }
for name, function := range funcMap {
this.funcMap[name] = function
}
}
}
return ctx.Err()