...

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

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

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

View as plain text