aboutsummaryrefslogtreecommitdiffhomepage
path: root/context.go
diff options
context:
space:
mode:
authorMatthew Holt <[email protected]>2020-05-06 13:18:56 -0600
committerMatthew Holt <[email protected]>2020-05-06 13:18:56 -0600
commit28ab0bfb13cb17ff1380ee9a2d688a1962591988 (patch)
tree94f26a6eedf3d0e0f292155d4703c13cf787895c /context.go
parent1c17e6c6bb30f730581708d9725aab7ca0a8c560 (diff)
downloadcaddy-28ab0bfb13cb17ff1380ee9a2d688a1962591988.tar.gz
caddy-28ab0bfb13cb17ff1380ee9a2d688a1962591988.zip
core: Support loading modules from [][]json.RawMessage fields
Diffstat (limited to 'context.go')
-rw-r--r--context.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/context.go b/context.go
index 5c8df51bb..c574be7d2 100644
--- a/context.go
+++ b/context.go
@@ -92,6 +92,7 @@ func (ctx *Context) OnCancel(f func()) {
//
// json.RawMessage => interface{}
// []json.RawMessage => []interface{}
+// [][]json.RawMessage => [][]interface{}
// map[string]json.RawMessage => map[string]interface{}
// []map[string]json.RawMessage => []map[string]interface{}
//
@@ -179,6 +180,27 @@ func (ctx Context) LoadModule(structPointer interface{}, fieldName string) (inte
}
result = all
+ } else if typ.Elem().Kind() == reflect.Slice && isJSONRawMessage(typ.Elem().Elem()) {
+ // val is `[][]json.RawMessage`
+
+ if inlineModuleKey == "" {
+ panic("unable to determine module name without inline_key because type is not a ModuleMap")
+ }
+ var all [][]interface{}
+ for i := 0; i < val.Len(); i++ {
+ innerVal := val.Index(i)
+ var allInner []interface{}
+ for j := 0; j < innerVal.Len(); j++ {
+ innerInnerVal, err := ctx.loadModuleInline(inlineModuleKey, moduleNamespace, innerVal.Index(j).Interface().(json.RawMessage))
+ if err != nil {
+ return nil, fmt.Errorf("position %d: %v", j, err)
+ }
+ allInner = append(allInner, innerInnerVal)
+ }
+ all = append(all, allInner)
+ }
+ result = all
+
} else if isModuleMapType(typ.Elem()) {
// val is `[]map[string]json.RawMessage`