func (h *structHandler) Handle(resp protocol.ResponseWriter, req *protocol.Request) { name := req.Method fh, ok := h.methods[name] if !ok { resp.SetError(protocol.UnknownMethod) return } fh.Handle(resp, req) }
func (m *recoverMiddleware) recover(rw protocol.ResponseWriter) { if err := recover(); err != nil { rw.SetError(protocol.InternalError) m.logger.WithFields(log.Fields{ "error": err, }).Error("Panic") if m.showStack { m.logger.Error(m.stacktrace()) } } }
func (h *methodHandler) Handle(resp protocol.ResponseWriter, req *protocol.Request) { params, err := h.parseParams(req) if err != nil { resp.SetError(err) return } data, err := h.call(params) if err != nil { resp.SetError(err) return } resp.Set(data) }
func (m *handlersMux) Handle(rw protocol.ResponseWriter, req *protocol.Request) { parsedMethod := strings.SplitN(req.Method, ".", 2) hdlrName := parsedMethod[0] hdlr, ok := m.hdlrs[hdlrName] if !ok { rw.SetError(fmt.Errorf("Unknown handler %q", hdlrName)) return } if len(parsedMethod) > 1 { req.Method = parsedMethod[1] } hdlr.Handle(rw, req) }