Exemplo n.º 1
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")
	}
}
Exemplo n.º 2
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()
}