mirror of
https://github.com/weaveworks/scope.git
synced 2026-03-02 01:30:30 +00:00
* New encoding format:
* Msgpack reports between probe<->app (smaller representation, faster to
encode/decode).
* Still use JSON between app<->UI (try to avoid making javascript deal with
mspack).
The app still suports publishing reports in both gob and JSON, not braking
backwards compatibility.
* Use compile-time generated marshallers/unmarshallers for higher performance. In
order to be able to skip code-generation for certain types, I included
https://github.com/2opremio/go-1/tree/master/codec/codecgen instead of
upstream until https://github.com/ugorji/go/pull/139 is merged.
* Encode/decode intermediate types using github.com/ugorji/go/codec.Selfer
for higher performance and reducing garbage collection (no temporary buffers).
20 lines
420 B
Go
20 lines
420 B
Go
package app
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/ugorji/go/codec"
|
|
|
|
log "github.com/Sirupsen/logrus"
|
|
)
|
|
|
|
func respondWith(w http.ResponseWriter, code int, response interface{}) {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.Header().Add("Cache-Control", "no-cache")
|
|
w.WriteHeader(code)
|
|
encoder := codec.NewEncoder(w, &codec.JsonHandle{})
|
|
if err := encoder.Encode(response); err != nil {
|
|
log.Error(err)
|
|
}
|
|
}
|