server: Rename responder to handler
This commit is contained in:
parent
2c7f8273e9
commit
5a784693ef
4
mux.go
4
mux.go
@ -170,7 +170,7 @@ func (mux *ServeMux) Handle(pattern string, handler Handler) {
|
|||||||
panic("gemini: invalid pattern")
|
panic("gemini: invalid pattern")
|
||||||
}
|
}
|
||||||
if handler == nil {
|
if handler == nil {
|
||||||
panic("gemini: nil responder")
|
panic("gemini: nil handler")
|
||||||
}
|
}
|
||||||
if _, exist := mux.m[pattern]; exist {
|
if _, exist := mux.m[pattern]; exist {
|
||||||
panic("gemini: multiple registrations for " + pattern)
|
panic("gemini: multiple registrations for " + pattern)
|
||||||
@ -204,7 +204,7 @@ func appendSorted(es []muxEntry, e muxEntry) []muxEntry {
|
|||||||
// HandleFunc registers the handler function for the given pattern.
|
// HandleFunc registers the handler function for the given pattern.
|
||||||
func (mux *ServeMux) HandleFunc(pattern string, handler func(ResponseWriter, *Request)) {
|
func (mux *ServeMux) HandleFunc(pattern string, handler func(ResponseWriter, *Request)) {
|
||||||
if handler == nil {
|
if handler == nil {
|
||||||
panic("gemini: nil responder")
|
panic("gemini: nil handler")
|
||||||
}
|
}
|
||||||
mux.Handle(pattern, HandlerFunc(handler))
|
mux.Handle(pattern, HandlerFunc(handler))
|
||||||
}
|
}
|
||||||
|
10
server.go
10
server.go
@ -78,7 +78,7 @@ func (srv *Server) Handle(pattern string, handler Handler) {
|
|||||||
panic("gemini: invalid pattern")
|
panic("gemini: invalid pattern")
|
||||||
}
|
}
|
||||||
if handler == nil {
|
if handler == nil {
|
||||||
panic("gemini: nil responder")
|
panic("gemini: nil handler")
|
||||||
}
|
}
|
||||||
if srv.handlers == nil {
|
if srv.handlers == nil {
|
||||||
srv.handlers = map[handlerKey]Handler{}
|
srv.handlers = map[handlerKey]Handler{}
|
||||||
@ -386,18 +386,18 @@ func (srv *Server) respond(conn net.Conn) {
|
|||||||
// Store remote address
|
// Store remote address
|
||||||
req.RemoteAddr = conn.RemoteAddr()
|
req.RemoteAddr = conn.RemoteAddr()
|
||||||
|
|
||||||
resp := srv.responder(req)
|
h := srv.handler(req)
|
||||||
if resp == nil {
|
if h == nil {
|
||||||
w.Status(StatusNotFound)
|
w.Status(StatusNotFound)
|
||||||
w.Flush()
|
w.Flush()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
resp.ServeGemini(w, req)
|
h.ServeGemini(w, req)
|
||||||
w.Flush()
|
w.Flush()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (srv *Server) responder(r *Request) Handler {
|
func (srv *Server) handler(r *Request) Handler {
|
||||||
if h, ok := srv.handlers[handlerKey{r.URL.Scheme, r.URL.Hostname()}]; ok {
|
if h, ok := srv.handlers[handlerKey{r.URL.Scheme, r.URL.Hostname()}]; ok {
|
||||||
return h
|
return h
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user