Environment configures providers
This commit is contained in:
parent
433a112875
commit
8084b7749a
@ -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,14 +36,17 @@ 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)
|
||||||
|
}
|
||||||
|
if provider, ok := provider.(FuncProvider); ok {
|
||||||
funcMap := provider.FuncMap()
|
funcMap := provider.FuncMap()
|
||||||
if funcMap == nil { continue }
|
if funcMap == nil { continue }
|
||||||
for name, function := range funcMap {
|
for name, function := range funcMap {
|
||||||
this.funcMap[name] = function
|
this.funcMap[name] = function
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return ctx.Err()
|
return ctx.Err()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user