MCPcopy Create free account
hub / github.com/PuerkitoBio/fetchbot / Handle

Method Handle

handler.go:71–101  ·  view source on GitHub ↗

Handle is the Handler interface implementation for Mux. It dispatches the calls to the matching Handler.

(ctx *Context, res *http.Response, err error)

Source from the content-addressed store, hash-verified

69// Handle is the Handler interface implementation for Mux. It dispatches the calls
70// to the matching Handler.
71func (mux *Mux) Handle(ctx *Context, res *http.Response, err error) {
72 mux.mu.RLock()
73 defer mux.mu.RUnlock()
74 if err != nil {
75 // Find a matching error handler
76 if h, ok := mux.errm[err]; ok {
77 h.Handle(ctx, res, err)
78 return
79 }
80 if h, ok := mux.errm[nil]; ok {
81 h.Handle(ctx, res, err)
82 return
83 }
84 } else {
85 // Find a matching response handler
86 var h Handler
87 var n = -1
88 for r := range mux.res {
89 if ok, cnt := r.match(res); ok {
90 if cnt > n {
91 h, n = r.h, cnt
92 }
93 }
94 }
95 if h != nil {
96 h.Handle(ctx, res, err)
97 return
98 }
99 }
100 mux.DefaultHandler.Handle(ctx, res, err)
101}
102
103// HandleError registers a Handler for a specific error value. Multiple calls
104// with the same error value override previous calls. As a special case, a nil

Callers

nothing calls this directly

Calls 2

HandleMethod · 0.95
matchMethod · 0.80

Tested by

no test coverage detected