micro-server-drpc/response.go
Vasiliy Tolstov d797edb9a7 add needed files
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2021-09-12 23:24:41 +03:00

35 lines
605 B
Go

package drpc
import (
"io"
"github.com/unistack-org/micro/v3/codec"
"github.com/unistack-org/micro/v3/metadata"
"github.com/unistack-org/micro/v3/server"
)
var _ server.Response = &rpcResponse{}
type rpcResponse struct {
rw io.ReadWriter
header metadata.Metadata
codec codec.Codec
}
func (r *rpcResponse) Codec() codec.Codec {
return r.codec
}
func (r *rpcResponse) WriteHeader(hdr metadata.Metadata) {
for k, v := range hdr {
r.header[k] = v
}
}
func (r *rpcResponse) Write(b []byte) error {
return r.codec.Write(r.rw, &codec.Message{
Header: r.header,
Body: b,
}, nil)
}