mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-16 21:56:40 -05:00
core: Support loading modules from [][]json.RawMessage fields
This commit is contained in:
parent
1c17e6c6bb
commit
28ab0bfb13
1 changed files with 22 additions and 0 deletions
22
context.go
22
context.go
|
@ -92,6 +92,7 @@ func (ctx *Context) OnCancel(f func()) {
|
||||||
//
|
//
|
||||||
// json.RawMessage => interface{}
|
// json.RawMessage => interface{}
|
||||||
// []json.RawMessage => []interface{}
|
// []json.RawMessage => []interface{}
|
||||||
|
// [][]json.RawMessage => [][]interface{}
|
||||||
// map[string]json.RawMessage => map[string]interface{}
|
// map[string]json.RawMessage => map[string]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
|
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()) {
|
} else if isModuleMapType(typ.Elem()) {
|
||||||
// val is `[]map[string]json.RawMessage`
|
// val is `[]map[string]json.RawMessage`
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue