goweb/service/template/data.go

20 lines
469 B
Go
Raw Normal View History

2018-12-06 15:18:05 +01:00
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
}