Exemple #1
0
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)
}
Exemple #2
0
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.
}
Exemple #3
0
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())
		}
	}
}
Exemple #4
0
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)
}
Exemple #5
0
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)
}
Exemple #6
0
func echoHandler(rw protocol.ResponseWriter, req *protocol.Request) {
	rw.Set(req.Params["msg"])
}