1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-06-12 22:07:47 +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

@ -5,6 +5,8 @@ import (
errs "errors"
"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/errors"
@ -65,9 +67,9 @@ var (
defaultContentType = "application/octet-stream"
defaultCodecs = map[string]codec.NewCodec{
"application/json": jsonrpc.NewCodec,
"application/protobuf": proto.NewCodec,
"application/json": json.NewCodec,
"application/json-rpc": jsonrpc.NewCodec,
"application/protobuf": protorpc.NewCodec,
"application/proto-rpc": protorpc.NewCodec,
"application/octet-stream": protorpc.NewCodec,
}
@ -110,7 +112,7 @@ func (c *rpcCodec) WriteRequest(req *request, body interface{}) error {
Method: req.ServiceMethod,
Type: codec.Request,
Header: map[string]string{
"X-Micro-Target": req.Service,
"X-Micro-Service": req.Service,
"X-Micro-Method": req.ServiceMethod,
},
}