@marcel91200 / caddy Mirror · read-only / commits / 28ab0bfb
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 14, 05:15 UTC

core: Support loading modules from [][]json.RawMessage fields

Matthew Holt committed May 6, 2020 at 13:18 UTC 28ab0bfb13cb17ff1380ee9a2d688a1962591988
1 file changed +22
context.go
+22
@@ -92,6 +92,7 @@ func (ctx *Context) OnCancel(f func()) {
92 //
93 // json.RawMessage => interface{}
94 // []json.RawMessage => []interface{}
95 +// [][]json.RawMessage => [][]interface{}
96 // map[string]json.RawMessage => map[string]interface{}
97 // []map[string]json.RawMessage => []map[string]interface{}
98 //
@@ -179,6 +180,27 @@ func (ctx Context) LoadModule(structPointer interface{}, fieldName string) (inte
180 }
181 result = all
182
183 + } else if typ.Elem().Kind() == reflect.Slice && isJSONRawMessage(typ.Elem().Elem()) {
184 + // val is `[][]json.RawMessage`
185 +
186 + if inlineModuleKey == "" {
187 + panic("unable to determine module name without inline_key because type is not a ModuleMap")
188 + }
189 + var all [][]interface{}
190 + for i := 0; i < val.Len(); i++ {
191 + innerVal := val.Index(i)
192 + var allInner []interface{}
193 + for j := 0; j < innerVal.Len(); j++ {
194 + innerInnerVal, err := ctx.loadModuleInline(inlineModuleKey, moduleNamespace, innerVal.Index(j).Interface().(json.RawMessage))
195 + if err != nil {
196 + return nil, fmt.Errorf("position %d: %v", j, err)
197 + }
198 + allInner = append(allInner, innerInnerVal)
199 + }
200 + all = append(all, allInner)
201 + }
202 + result = all
203 +
204 } else if isModuleMapType(typ.Elem()) {
205 // val is `[]map[string]json.RawMessage`
206