func loadLocalHostMapping(file string) error { ini, err := util.LoadIniFile(file) if nil != err { return err } props, exist := ini.GetTagProperties("") if exist { for k, _ := range props { selector := &util.ListSelector{} vs, _ := ini.GetProperty("", k) hs := strings.Split(vs, "|") for _, h := range hs { selector.Add(h) } if strings.Contains(k, "*") { rh := new(regexHost) var err error if rh.regex, err = util.PrepareRegexp(k, true); nil != err { log.Printf("[ERROR]Invalid regex host pattern:%s for reason:%v\n", k, err) continue } rh.selector = selector regexMappingArray = append(regexMappingArray, rh) } else { mapping[k] = selector } } } return nil }
func (r *urlRegexRule) init(rule string) (err error) { if r.is_raw_regex { r.url_reg, err = regexp.Compile(rule) } else { r.url_reg, err = util.PrepareRegexp(rule, false) } return }
func initHostMatchRegex(pattern string) []*regexp.Regexp { regexs := []*regexp.Regexp{} ps := strings.Split(strings.TrimSpace(pattern), "|") for _, p := range ps { reg, err := util.PrepareRegexp(p, true) if nil != err { log.Printf("[ERROR]Invalid pattern:%s for reason:%v\n", p, err) } else { regexs = append(regexs, reg) } } return regexs }
func initRegexSlice(rules []string) ([]*regexp.Regexp, error) { regexs := make([]*regexp.Regexp, 0) for _, originrule := range rules { reg, err := util.PrepareRegexp(originrule, true) if nil != err { log.Printf("Invalid pattern:%s for reason:%v\n", originrule, err) return nil, err } else { regexs = append(regexs, reg) } } return regexs, nil }