improve codegen for JSON serialization of response/request modifiers

This commit is contained in:
Kevin Pham
2023-12-04 11:10:55 -06:00
parent 7883b32335
commit c28470e619
5 changed files with 344 additions and 304 deletions

View File

@@ -34,11 +34,24 @@ func (rule *Rule) UnmarshalJSON(data []byte) error {
if err != nil {
return fmt.Errorf("Rule::UnmarshalJSON invalid function call syntax => '%s'", err)
}
f, exists := resModMap[name]
f, exists := rsmModMap[name]
if !exists {
return fmt.Errorf("Rule::UnmarshalJSON => responseModifer '%s' does not exist, please check spelling", err)
}
rule.ResponseModifications = append(rule.ResponseModifications, f(params...))
}
// convert responseModification function call string into actual functional option
for _, rqmModStr := range aux.RequestModifications {
name, params, err := parseFuncCall(rqmModStr)
if err != nil {
return fmt.Errorf("Rule::UnmarshalJSON invalid function call syntax => '%s'", err)
}
f, exists := rqmModMap[name]
if !exists {
return fmt.Errorf("Rule::UnmarshalJSON => requestModifier '%s' does not exist, please check spelling", err)
}
rule.ResponseModifications = append(rule.ResponseModifications, f(params...))
rule.RequestModifications = append(rule.RequestModifications, f(params...))
}
return nil