Пример #1
0
func AddFunc(name string, i interface{}) {
	if _, ok := extFunc[name]; !ok {
		extFunc[name] = i
	} else {
		log.Warn("<AddFunc> ", "func:"+name+" be added,do not repeat to add")
	}
}
Пример #2
0
func (s *site) AddTemplateFunc(name string, i interface{}) {
	_, ok := s.templateFunc[name]
	if !ok {
		s.templateFunc[name] = i
	} else {
		log.Warn("<site.AddTemplateFunc> ", "func:"+name+" be added,do not repeat to add")
	}
}
Пример #3
0
func (u *UrlManage) addRule(expr, replace string, flags ...flag) {
	if expr == "" || replace == "" {
		log.Warn("UrlManage.addUrl: expr and reolace is empty")
		return
	}

	r, err := regexp.Compile(expr)
	if err != nil {
		log.Warn("UrlManage.addUrl: regexp compile failed - ", err)
		return
	}

	rl := rule{
		regexp:  r,
		replace: replace,
		flags:   flags,
	}

	u.mutex.Lock()
	u.rules = append(u.rules, rl)
	u.mutex.Unlock()
}