// HandleReferral adds a new ReferralHandler to the Messenger
544091
func (m *Messenger) HandleReferral(f ReferralHandler) {
	m.referralHandlers = append(m.referralHandlers, f)
}
1361891
func (mux *ServeMux) Handler(r *Request) Handler {
	var matcher Matcher
	var entry *muxEntry

	// Acquire a read lock to ensure that list would not
	// be modified during the search of registered handler.
	mux.mu.RLock()
	var matched bool

	// Try to match the processing request to any of the registered
	// filters.
	for matcher, entry = range mux.handlers {
		if matched = matcher.Match(r); matched {
			break
		}
	}

	mux.mu.RUnlock()

	// Use the DefaultHandler when there are no matching entries in the list.
	if !matched {
		return DefaultHandler
	}

	// If the retrieved entry is not disposable one, we will
	// return it as is without any processing.
	if !entry.once {
		return entry.handler
	}

	// But when the entry is disposable, we need to remove it
	// from the list.

	// We need to acquire the write lock in order to remove the
	// entry from the root. This procedure does not guarantee,
	// that handler will process the first message.
	mux.mu.Lock()
	defer mux.mu.Unlock()

	// If the concurrent message have already started the message
	// processing, it will be no longer presented in the list.
	if _, ok := mux.handlers[matcher]; !ok {
		return DiscardHandler
	}

	// Remove the entry from the list if it is marked as disposable.
	delete(mux.handlers, matcher)
	return entry.handler
}
922209
func (t Type) Handler(ctx context.Context, msg string) error {
	var tm typedMessage
	err := json.Unmarshal([]byte(msg), &tm)
	if err != nil {
		return err
	}
	if tm.Type == "" {
		return RouteNotFoundError{tm.Type}
	}

	fn, ok := t[tm.Type]
	if !ok {
		return RouteNotFoundError{tm.Type}
	}

	return fn(ctx, msg)
}
95335
func MessageHandler(Incoming <-chan tgbot.MessageWithUpdateID, bot *tgbot.TgBot) {
	for {
		input := <-Incoming

		if input.Msg.Text != nil {
			text := handleMessageText(*input.Msg.Text, input.Msg)
			if text != "" {
				nmsg, err := bot.SimpleSendMessage(input.Msg, text)
				if err != nil {
					fmt.Println(err)
					continue
				}
				fmt.Println(nmsg.String())
			}
		}
	}
}
522193
func (b *Bot) HandleFunc(cmd string, handler func(s Sender, m *irc.Message)) {
	b.handlers[cmd] = append(b.handlers[cmd], HandlerFunc(handler))
}
4521
func (c *Client) callOnConnectHandlers() {
	c.m.RLock()
	defer c.m.RUnlock()

	for _, handler := range c.onConnectHandlers {
		func() {
			defer nopRecover()
			handler()
		}()
	}
}
629476
func (m *Messenger) HandleRead(f ReadHandler) {
	m.readHandlers = append(m.readHandlers, f)
}
510743
func (p *Provider) handleCallback(rw http.ResponseWriter, req *http.Request, _ router.Params) error {
	// oauth handshake
	code := req.FormValue("code")
	accessToken, err := p.Config.Exchange(oauth2.NoContext, code)
	if err != nil {
		return errors.Wrap(err)
	}
	var state string
	encState := req.FormValue("state")
	if encState != "" {
		stateByte, err := base64.StdEncoding.DecodeString(encState)
		if err != nil {
			return errors.New("error decoding state: %s", err)
		}
		state = string(stateByte)
	}
	err = p.PostCallback(req, rw, accessToken, state)
	if err != nil {
		return errors.Wrap(err)
	}
	return nil
}
1338821
func (m *Messenger) HandleDelivery(f DeliveryHandler) {
	m.deliveryHandlers = append(m.deliveryHandlers, f)
}
1136563
func (service *BaseService) AddBeforeFilterHandler(handler ...FilterHandler) Service {
	service.handlerManager.AddBeforeFilterHandler(handler...)
	return service
}
705352
func (m *Mux) HandlerFunc(h http.Handler) http.HandlerFunc {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		h.ServeHTTP(w, r)
	})
}
708039
func (ctx *context) GetReferrer() Referrer {
	// the underline net/http follows the https://tools.ietf.org/html/rfc7231#section-5.5.2,
	// so there is nothing special left to do.
	// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy
	refURL := ctx.GetHeader("Referer")
	if refURL == "" {
		refURL = ctx.URLParam("referer")
	}

	if ref := goreferrer.DefaultRules.Parse(refURL); ref.Type > goreferrer.Invalid {
		return Referrer{
			Type:       ReferrerType(ref.Type),
			Label:      ref.Label,
			URL:        ref.URL,
			Subdomain:  ref.Subdomain,
			Domain:     ref.Domain,
			Tld:        ref.Tld,
			Path:       ref.Path,
			Query:      ref.Query,
			GoogleType: ReferrerGoogleSearchType(ref.GoogleType),
		}
	}

	return emptyReferrer
}
543599
func (ps *Store) CallHandler(p *v2.Plugin) {
	for _, typ := range p.GetTypes() {
		for _, handler := range ps.handlers[typ.String()] {
			handler(p.Name(), p.Client())
		}
	}
}
762551
func (r *Route) HandlerFunc(f func(context.Context, http.ResponseWriter, *http.Request) error) *Route {
	return r.Handler(HandlerFunc(f))
}
666640
func (a *AddrManager) addressHandler() {
	dumpAddressTicker := time.NewTicker(dumpAddressInterval)
	defer dumpAddressTicker.Stop()
out:
	for {
		select {
		case <-dumpAddressTicker.C:
			a.savePeers()

		case <-a.quit:
			break out
		}
	}
	a.savePeers()
	a.wg.Done()
	log.Trace("Address handler done")
}
1083760
func HandlerFunc(log func(message string, time time.Time, level LogLevel, call CallStack, context ContextMap) error) LogHandler {
	return remoteHandler(log)
}
23983
func (ref *Consumer) manualErrorHandler(in <-chan *sarama.ConsumerError) {
	ref.Debug("errorHandler started ...")
	for {
		select {
		case err, more := <-in:
			if more {
				ref.Errorf("message error: %T, %v", err, err)
				ref.Config.RecvErrorChan <- err
			}
		case <-ref.closeChannel:
			ref.Debug("Canceling error handler")
			return
		}
	}
}