示例#1
0
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
}
示例#2
0
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
}
示例#3
0
文件: common.go 项目: juju2013/gsnova
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
}
示例#4
0
文件: spac.go 项目: juju2013/gsnova
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
}