| 52 | } |
| 53 | |
| 54 | func (d *strategyDriver) Check(config interface{}) error { |
| 55 | if config == nil { |
| 56 | return nil |
| 57 | } |
| 58 | data, err := json.Marshal(config) |
| 59 | if err != nil { |
| 60 | return err |
| 61 | } |
| 62 | var cfg Config |
| 63 | err = json.Unmarshal(data, &cfg) |
| 64 | if err != nil { |
| 65 | return err |
| 66 | } |
| 67 | for _, r := range cfg.Rules { |
| 68 | if r.Match == nil { |
| 69 | return errors.New("match can't be null. ") |
| 70 | } |
| 71 | if r.Mask == nil { |
| 72 | return errors.New("mask can't be null. ") |
| 73 | } |
| 74 | |
| 75 | if _, ok := validMatchTypes[r.Match.Type]; !ok { |
| 76 | return fmt.Errorf("match type %s is illegal. ", r.Match.Type) |
| 77 | } |
| 78 | |
| 79 | if r.Match.Type == "inner" { |
| 80 | if _, ok := validMatchInnerValues[r.Match.Value]; !ok { |
| 81 | return fmt.Errorf("match value %s is illegal. ", r.Match.Value) |
| 82 | } |
| 83 | } |
| 84 | if _, ok := validMaskTypes[r.Mask.Type]; !ok { |
| 85 | return fmt.Errorf("mask type %s is illegal. ", r.Mask.Type) |
| 86 | } |
| 87 | if r.Mask.Replace != nil { |
| 88 | if _, ok := validReplaceTypes[r.Mask.Replace.Type]; !ok { |
| 89 | return fmt.Errorf("replace type %s is illegal. ", r.Mask.Replace.Type) |
| 90 | } |
| 91 | } |
| 92 | } |
| 93 | return nil |
| 94 | } |