summaryrefslogtreecommitdiffstats
path: root/tpl
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-07-12 11:26:51 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-07-12 13:43:27 +0200
commit306573def0e20ec16ee5c447981cc09ed8bb7ec7 (patch)
tree86c5a0bc8ab092b58d14f35d2d4fd8b5bd17c742 /tpl
parent80c8f3b81a9849080e64bf877288ede28d960d3f (diff)
Improve type support in resources.Concat
This allows the result of `.Resources.Match` and similar to be concatenated. Fixes #4934
Diffstat (limited to 'tpl')
-rw-r--r--tpl/resources/resources.go33
1 files changed, 26 insertions, 7 deletions
diff --git a/tpl/resources/resources.go b/tpl/resources/resources.go
index 5d4f6e315..c9d3275e5 100644
--- a/tpl/resources/resources.go
+++ b/tpl/resources/resources.go
@@ -79,19 +79,38 @@ func (ns *Namespace) Get(filename interface{}) (resource.Resource, error) {
// Concat concatenates a slice of Resource objects. These resources must
// (currently) be of the same Media Type.
-func (ns *Namespace) Concat(targetPathIn interface{}, r []interface{}) (resource.Resource, error) {
+func (ns *Namespace) Concat(targetPathIn interface{}, r interface{}) (resource.Resource, error) {
targetPath, err := cast.ToStringE(targetPathIn)
if err != nil {
return nil, err
}
- rr := make([]resource.Resource, len(r))
- for i := 0; i < len(r); i++ {
- rv, ok := r[i].(resource.Resource)
- if !ok {
- return nil, fmt.Errorf("cannot concat type %T", rv)
+
+ var rr resource.Resources
+
+ switch v := r.(type) {
+ // This is what we get from the slice func.
+ case []interface{}:
+ rr = make([]resource.Resource, len(v))
+ for i := 0; i < len(v); i++ {
+ rv, ok := v[i].(resource.Resource)
+ if !ok {
+ return nil, fmt.Errorf("cannot concat type %T", v[i])
+ }
+ rr[i] = rv
}
- rr[i] = rv
+ // This is what we get from .Resources.Match etc.
+ case resource.Resources:
+ rr = v
+ default:
+ // We may support Page collections at one point, but we need to think about ...
+ // what to acutually concatenate.
+ return nil, fmt.Errorf("slice %T not supported in concat", r)
}
+
+ if len(rr) == 0 {
+ return nil, errors.New("must provide one or more Resource objects to concat")
+ }
+
return ns.bundlerClient.Concat(targetPath, rr)
}