1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-06-18 22:17:44 +02:00

Make json/protobuf codecs

This commit is contained in:
Asim Aslam
2018-12-31 22:01:16 +00:00
parent b3b4bc6059
commit e2623d8ef5
4 changed files with 105 additions and 5 deletions

View File

@ -4,6 +4,8 @@ import (
"bytes"
"github.com/micro/go-micro/codec"
"github.com/micro/go-micro/codec/json"
"github.com/micro/go-micro/codec/proto"
"github.com/micro/go-micro/codec/jsonrpc"
"github.com/micro/go-micro/codec/protorpc"
"github.com/micro/go-micro/transport"
@ -25,9 +27,9 @@ type readWriteCloser struct {
var (
defaultCodecs = map[string]codec.NewCodec{
"application/json": jsonrpc.NewCodec,
"application/json": json.NewCodec,
"application/json-rpc": jsonrpc.NewCodec,
"application/protobuf": protorpc.NewCodec,
"application/protobuf": proto.NewCodec,
"application/proto-rpc": protorpc.NewCodec,
"application/octet-stream": protorpc.NewCodec,
}
@ -77,6 +79,10 @@ func (c *rpcCodec) ReadRequestHeader(r *request, first bool) error {
m.Header = tm.Header
}
// set some internal things
m.Target = m.Header["X-Micro-Service"]
m.Method = m.Header["X-Micro-Method"]
err := c.codec.ReadHeader(&m, codec.Request)
r.ServiceMethod = m.Method
r.Seq = m.Id