work on rule reqmod resmod codegen for serialization
This commit is contained in:
49
proxychain/ruleset/rule.go
Normal file
49
proxychain/ruleset/rule.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package ruleset_v2
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"ladder/proxychain"
|
||||
)
|
||||
|
||||
type Rule struct {
|
||||
Domains []string
|
||||
RequestModifications []proxychain.RequestModification
|
||||
ResponseModifications []proxychain.ResponseModification
|
||||
}
|
||||
|
||||
// implement type encoding/json/Marshaler
|
||||
func (rule *Rule) UnmarshalJSON(data []byte) error {
|
||||
type Aux struct {
|
||||
Domains []string `json:"domains"`
|
||||
RequestModifications []string `json:"request_modifications"`
|
||||
ResponseModifications []string `json:"response_modifications"`
|
||||
}
|
||||
|
||||
aux := &Aux{}
|
||||
if err := json.Unmarshal(data, aux); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
//fmt.Println(aux.Domains)
|
||||
rule.Domains = aux.Domains
|
||||
|
||||
// convert requestModification function call string into actual functional option
|
||||
for _, resModStr := range aux.RequestModifications {
|
||||
name, params, err := parseFuncCall(resModStr)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Rule::UnmarshalJSON invalid function call syntax => '%s'", err)
|
||||
}
|
||||
f, exists := resModMap[name]
|
||||
if !exists {
|
||||
return fmt.Errorf("Rule::UnmarshalJSON => requestModifier '%s' does not exist, please check spelling", err)
|
||||
}
|
||||
rule.ResponseModifications = append(rule.ResponseModifications, f(params...))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *Rule) MarshalJSON() ([]byte, error) {
|
||||
return []byte{}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user