| 40 | ) |
| 41 | |
| 42 | func CheckFilters(name string, scope strategy_dto.Scope, filters []*strategy_dto.Filter) error { |
| 43 | fs, ok := filterHandler.Options(scope.String()) |
| 44 | if !ok { |
| 45 | return fmt.Errorf("unknown scope %s", scope) |
| 46 | } |
| 47 | filterNameSet := make(map[string]struct{}) |
| 48 | for _, filter := range filters { |
| 49 | op, ok := fs[filter.Name] |
| 50 | if !ok { |
| 51 | return fmt.Errorf("%s filter %s not found", name, filter.Name) |
| 52 | } |
| 53 | for _, value := range filter.Values { |
| 54 | if op.Pattern != nil && !op.Pattern.MatchString(value) { |
| 55 | return fmt.Errorf("%s filter %s value %s not match pattern", name, filter.Name, value) |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | if len(filter.Values) == 0 { |
| 60 | return fmt.Errorf("%s.Options can't be null. filter.Name:%s ", name, filter.Name) |
| 61 | } |
| 62 | |
| 63 | if _, has := filterNameSet[filter.Name]; has { |
| 64 | return fmt.Errorf("%s.Name %s is reduplicative. ", name, filter.Name) |
| 65 | } |
| 66 | filterNameSet[filter.Name] = struct{}{} |
| 67 | } |
| 68 | |
| 69 | return nil |
| 70 | } |
| 71 | |
| 72 | type OptionTitle struct { |
| 73 | Field string `json:"field"` |