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 *traceMiddleware) Handle(rw protocol.ResponseWriter, req *protocol.Request) { m.wrapped.Handle(rw, req) traceId := req.Header.Get(TraceHeader) if traceId == "" { traceId = uuid.New() } rw.Header().Set(TraceHeader, traceId) // TODO: Logging with trace id. }
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 (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) }
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 echoHandler(rw protocol.ResponseWriter, req *protocol.Request) { rw.Set(req.Params["msg"]) }