mirror of
https://github.com/foomo/gotsrpc.git
synced 2025-10-16 12:35:35 +00:00
41 lines
730 B
Go
41 lines
730 B
Go
package gotsrpc
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/ugorji/go/codec"
|
|
)
|
|
|
|
var (
|
|
msgpackHandle = &codec.MsgpackHandle{
|
|
RawToString: true,
|
|
}
|
|
msgpackContentType = "application/msgpack; charset=utf-8"
|
|
)
|
|
|
|
var (
|
|
jsonHandle = &codec.JsonHandle{
|
|
MapKeyAsString: true,
|
|
}
|
|
jsonContentType = "application/json; charset=utf-8"
|
|
)
|
|
|
|
type responseWriterWithLength struct {
|
|
http.ResponseWriter
|
|
length int
|
|
}
|
|
|
|
func newResponseWriterWithLength(w http.ResponseWriter) *responseWriterWithLength {
|
|
return &responseWriterWithLength{w, 0}
|
|
}
|
|
|
|
func (w *responseWriterWithLength) Write(b []byte) (n int, err error) {
|
|
n, err = w.ResponseWriter.Write(b)
|
|
w.length += n
|
|
return
|
|
}
|
|
|
|
func (w *responseWriterWithLength) Length() int {
|
|
return w.length
|
|
}
|