...

Source file src/github.com/grpc-ecosystem/grpc-gateway/codegenerator/parse_req.go

Documentation: github.com/grpc-ecosystem/grpc-gateway/codegenerator

     1  package codegenerator
     2  
     3  import (
     4  	"fmt"
     5  	"io"
     6  	"io/ioutil"
     7  
     8  	"github.com/golang/protobuf/proto"
     9  	plugin "github.com/golang/protobuf/protoc-gen-go/plugin"
    10  )
    11  
    12  // ParseRequest parses a code generator request from a proto Message.
    13  func ParseRequest(r io.Reader) (*plugin.CodeGeneratorRequest, error) {
    14  	input, err := ioutil.ReadAll(r)
    15  	if err != nil {
    16  		return nil, fmt.Errorf("failed to read code generator request: %v", err)
    17  	}
    18  	req := new(plugin.CodeGeneratorRequest)
    19  	if err = proto.Unmarshal(input, req); err != nil {
    20  		return nil, fmt.Errorf("failed to unmarshal code generator request: %v", err)
    21  	}
    22  	return req, nil
    23  }
    24  

View as plain text