Example #1
0
func New(fs []string) *Matcher {
	f := &Matcher{make([]glob.Glob, len(fs))}
	for i, v := range fs {
		f.globs[i] = glob.MustCompile(v)
	}
	return f
}
Example #2
0
func mapRouteHandler(pattern string, handlers []Handler) []Handler {
	var mapped []Handler

	g := glob.MustCompile(pattern)
	for _, handler := range handlers {
		mapped = append(mapped, HandlerFunc(func(ctrl *Control, bot *tgbotapi.BotAPI, update tgbotapi.Update) {
			if g.Match(update.Message.Text) {
				handler.Serve(ctrl, bot, update)
			} else {
				ctrl.Next()
			}
		}))
	}

	return mapped
}
Example #3
0
func newWsHandler(c Config, r Responder) *wsHandler {
	u := websocket.Upgrader{}

	if c.Origin != "" {
		originChecker := glob.MustCompile(c.Origin)
		u.CheckOrigin = func(r *http.Request) bool {
			return originChecker.Match(r.Header.Get(headerOrigin))
		}
	}

	return &wsHandler{
		upgrader:  u,
		config:    c,
		responder: r,
	}
}