20 lines
469 B
Go
20 lines
469 B
Go
|
package template
|
||
|
|
||
|
// Data is some data to inject into the template
|
||
|
type Data map[string]interface{}
|
||
|
|
||
|
// DataExtFunc is some extensions to a template's data
|
||
|
type DataExtFunc func(data Data) (Data, error)
|
||
|
|
||
|
// Extend returns a template's data with the given extensions
|
||
|
func Extend(data Data, extensions ...DataExtFunc) (Data, error) {
|
||
|
var err error
|
||
|
for _, ext := range extensions {
|
||
|
data, err = ext(data)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
}
|
||
|
return data, nil
|
||
|
}
|