package grpcall import ( "encoding/json" "fmt" "io" "github.com/golang/protobuf/jsonpb" "github.com/golang/protobuf/proto" ) type RequestData func(msg proto.Message) error type RequestParser interface { Next(msg proto.Message) error } type JsonRequestParser struct { dec *json.Decoder unmarshaler jsonpb.Unmarshaler } func (this JsonRequestParser) Next(msg proto.Message) error { if err := this.unmarshaler.UnmarshalNext(this.dec, msg); err != nil { if err == io.EOF { return err } return fmt.Errorf("unmarshal request json data error, %s", err) } return nil } func NewJsonRequestParser(resolver jsonpb.AnyResolver, in io.Reader) RequestParser { return &JsonRequestParser{ dec: json.NewDecoder(in), unmarshaler: jsonpb.Unmarshaler{AnyResolver: resolver}, } }