github.com/renbou/grpcbridge@v0.0.2-0.20240416012907-bcbd8b12648a/internal/bridgetest/testpb/testsvc.go (about) 1 package testpb 2 3 import ( 4 context "context" 5 6 "google.golang.org/protobuf/proto" 7 ) 8 9 func PrepareResponse[T proto.Message](response T, err error) *PreparedResponse[T] { 10 return &PreparedResponse[T]{Response: response, Error: err} 11 } 12 13 type PreparedResponse[T proto.Message] struct { 14 Response T 15 Error error 16 } 17 18 // TestService implements the test gRPC service with handlers which simply record the requests and return predetermined responses. 19 type TestService struct { 20 UnimplementedTestServiceServer 21 UnaryBoundRequest *Scalars 22 UnaryBoundResponse *PreparedResponse[*Combined] 23 } 24 25 func (s *TestService) UnaryBound(ctx context.Context, req *Scalars) (*Combined, error) { 26 s.UnaryBoundRequest = req 27 return s.UnaryBoundResponse.Response, s.UnaryBoundResponse.Error 28 } 29 30 func (s *TestService) BadResponsePath(context.Context, *Scalars) (*Combined, error) { 31 return new(Combined), nil 32 } 33 34 func (s *TestService) Echo(ctx context.Context, req *Combined) (*Combined, error) { 35 return req, nil 36 }