Merge pull request #29 from dsymonds/master

Switch to new package layout and import path.
This commit is contained in:
Qi Zhao 2015-02-08 17:58:09 -08:00
commit dd172600a0
50 changed files with 160 additions and 160 deletions

View File

@ -2,4 +2,4 @@ gRPC-Go: a Go implementation of gRPC, Google's RPC library
To install this package, you need to install Go 1.4 and setup your Go workspace on your computer. The simplest way to install the library is to run: To install this package, you need to install Go 1.4 and setup your Go workspace on your computer. The simplest way to install the library is to run:
go get github.com/grpc/grpc-go/rpc go get google.golang.org/grpc

View File

@ -31,15 +31,15 @@
* *
*/ */
package rpc package grpc
import ( import (
"io" "io"
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
"github.com/grpc/grpc-go/rpc/codes" "google.golang.org/grpc/codes"
"github.com/grpc/grpc-go/rpc/metadata" "google.golang.org/grpc/metadata"
"github.com/grpc/grpc-go/rpc/transport" "google.golang.org/grpc/transport"
"golang.org/x/net/context" "golang.org/x/net/context"
) )

View File

@ -31,18 +31,15 @@
* *
*/ */
/* package grpc
Package rpc implements various components to perform RPC on top of transport package.
*/
package rpc
import ( import (
"fmt" "fmt"
"sync" "sync"
"time" "time"
"github.com/grpc/grpc-go/rpc/credentials" "google.golang.org/grpc/credentials"
"github.com/grpc/grpc-go/rpc/transport" "google.golang.org/grpc/transport"
"golang.org/x/net/context" "golang.org/x/net/context"
) )

View File

@ -617,7 +617,7 @@ string GetServices(const google::protobuf::FileDescriptor* file,
"\t\"io\"\n"); "\t\"io\"\n");
} }
printer.Print( printer.Print(
"\t\"github.com/google/grpc-go/rpc\"\n" "\t\"google.golang.org/grpc\"\n"
"\tcontext \"golang.org/x/net/context\"\n" "\tcontext \"golang.org/x/net/context\"\n"
"\tproto \"github.com/golang/protobuf/proto\"\n" "\tproto \"github.com/golang/protobuf/proto\"\n"
")\n\n"); ")\n\n");

6
doc.go Normal file
View File

@ -0,0 +1,6 @@
/*
Package grpc implements an RPC system called gRPC.
See https://github.com/grpc/grpc for more information about gRPC.
*/
package grpc

View File

@ -41,10 +41,10 @@ import (
"strconv" "strconv"
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
"github.com/grpc/grpc-go/rpc"
"github.com/grpc/grpc-go/rpc/credentials"
testpb "github.com/grpc/grpc-go/rpc/interop/testdata"
"golang.org/x/net/context" "golang.org/x/net/context"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
testpb "google.golang.org/grpc/interop/testdata"
) )
var ( var (
@ -225,7 +225,7 @@ func doPingPong(tc testpb.TestServiceClient) {
func main() { func main() {
flag.Parse() flag.Parse()
serverAddr := net.JoinHostPort(*serverHost, strconv.Itoa(*serverPort)) serverAddr := net.JoinHostPort(*serverHost, strconv.Itoa(*serverPort))
var opts []rpc.DialOption var opts []grpc.DialOption
if *useTLS { if *useTLS {
var sn string var sn string
if *tlsServerName != "" { if *tlsServerName != "" {
@ -241,9 +241,9 @@ func main() {
} else { } else {
creds = credentials.NewClientTLSFromCert(nil, sn) creds = credentials.NewClientTLSFromCert(nil, sn)
} }
opts = append(opts, rpc.WithClientTLS(creds)) opts = append(opts, grpc.WithClientTLS(creds))
} }
conn, err := rpc.Dial(serverAddr, opts...) conn, err := grpc.Dial(serverAddr, opts...)
if err != nil { if err != nil {
log.Fatalf("fail to dial: %v", err) log.Fatalf("fail to dial: %v", err)
} }

View File

@ -42,11 +42,11 @@ import (
"strconv" "strconv"
"time" "time"
"github.com/grpc/grpc-go/rpc/credentials"
testpb "github.com/grpc/grpc-go/rpc/interop/testdata"
"github.com/grpc/grpc-go/rpc"
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
"golang.org/x/net/context" "golang.org/x/net/context"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
testpb "google.golang.org/grpc/interop/testdata"
) )
var ( var (
@ -195,7 +195,7 @@ func main() {
if err != nil { if err != nil {
log.Fatalf("failed to listen: %v", err) log.Fatalf("failed to listen: %v", err)
} }
server := rpc.NewServer() server := grpc.NewServer()
testpb.RegisterService(server, &testServer{}) testpb.RegisterService(server, &testServer{})
if *useTLS { if *useTLS {
creds, err := credentials.NewServerTLSFromFile(*certFile, *keyFile) creds, err := credentials.NewServerTLSFromFile(*certFile, *keyFile)

View File

@ -35,49 +35,49 @@ package grpc_testing
import ( import (
"fmt" "fmt"
"github.com/grpc/grpc-go/rpc"
proto "github.com/golang/protobuf/proto" proto "github.com/golang/protobuf/proto"
context "golang.org/x/net/context" context "golang.org/x/net/context"
"google.golang.org/grpc"
"io" "io"
) )
type TestServiceClient interface { type TestServiceClient interface {
EmptyCall(ctx context.Context, in *Empty, opts ...rpc.CallOption) (*Empty, error) EmptyCall(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*Empty, error)
UnaryCall(ctx context.Context, in *SimpleRequest, opts ...rpc.CallOption) (*SimpleResponse, error) UnaryCall(ctx context.Context, in *SimpleRequest, opts ...grpc.CallOption) (*SimpleResponse, error)
StreamingOutputCall(ctx context.Context, m *StreamingOutputCallRequest, opts ...rpc.CallOption) (TestService_StreamingOutputCallClient, error) StreamingOutputCall(ctx context.Context, m *StreamingOutputCallRequest, opts ...grpc.CallOption) (TestService_StreamingOutputCallClient, error)
StreamingInputCall(ctx context.Context, opts ...rpc.CallOption) (TestService_StreamingInputCallClient, error) StreamingInputCall(ctx context.Context, opts ...grpc.CallOption) (TestService_StreamingInputCallClient, error)
FullDuplexCall(ctx context.Context, opts ...rpc.CallOption) (TestService_FullDuplexCallClient, error) FullDuplexCall(ctx context.Context, opts ...grpc.CallOption) (TestService_FullDuplexCallClient, error)
HalfDuplexCall(ctx context.Context, opts ...rpc.CallOption) (TestService_HalfDuplexCallClient, error) HalfDuplexCall(ctx context.Context, opts ...grpc.CallOption) (TestService_HalfDuplexCallClient, error)
} }
type testServiceClient struct { type testServiceClient struct {
cc *rpc.ClientConn cc *grpc.ClientConn
} }
func NewTestServiceClient(cc *rpc.ClientConn) TestServiceClient { func NewTestServiceClient(cc *grpc.ClientConn) TestServiceClient {
return &testServiceClient{cc} return &testServiceClient{cc}
} }
func (c *testServiceClient) EmptyCall(ctx context.Context, in *Empty, opts ...rpc.CallOption) (*Empty, error) { func (c *testServiceClient) EmptyCall(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*Empty, error) {
out := new(Empty) out := new(Empty)
err := rpc.Invoke(ctx, "/grpc.testing.TestService/EmptyCall", in, out, c.cc, opts...) err := grpc.Invoke(ctx, "/grpc.testing.TestService/EmptyCall", in, out, c.cc, opts...)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return out, nil return out, nil
} }
func (c *testServiceClient) UnaryCall(ctx context.Context, in *SimpleRequest, opts ...rpc.CallOption) (*SimpleResponse, error) { func (c *testServiceClient) UnaryCall(ctx context.Context, in *SimpleRequest, opts ...grpc.CallOption) (*SimpleResponse, error) {
out := new(SimpleResponse) out := new(SimpleResponse)
err := rpc.Invoke(ctx, "/grpc.testing.TestService/UnaryCall", in, out, c.cc, opts...) err := grpc.Invoke(ctx, "/grpc.testing.TestService/UnaryCall", in, out, c.cc, opts...)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return out, nil return out, nil
} }
func (c *testServiceClient) StreamingOutputCall(ctx context.Context, m *StreamingOutputCallRequest, opts ...rpc.CallOption) (TestService_StreamingOutputCallClient, error) { func (c *testServiceClient) StreamingOutputCall(ctx context.Context, m *StreamingOutputCallRequest, opts ...grpc.CallOption) (TestService_StreamingOutputCallClient, error) {
stream, err := rpc.NewClientStream(ctx, c.cc, "/grpc.testing.TestService/StreamingOutputCall", opts...) stream, err := grpc.NewClientStream(ctx, c.cc, "/grpc.testing.TestService/StreamingOutputCall", opts...)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -93,11 +93,11 @@ func (c *testServiceClient) StreamingOutputCall(ctx context.Context, m *Streamin
type TestService_StreamingOutputCallClient interface { type TestService_StreamingOutputCallClient interface {
Recv() (*StreamingOutputCallResponse, error) Recv() (*StreamingOutputCallResponse, error)
rpc.ClientStream grpc.ClientStream
} }
type testServiceStreamingOutputCallClient struct { type testServiceStreamingOutputCallClient struct {
rpc.ClientStream grpc.ClientStream
} }
func (x *testServiceStreamingOutputCallClient) Recv() (*StreamingOutputCallResponse, error) { func (x *testServiceStreamingOutputCallClient) Recv() (*StreamingOutputCallResponse, error) {
@ -108,8 +108,8 @@ func (x *testServiceStreamingOutputCallClient) Recv() (*StreamingOutputCallRespo
return m, nil return m, nil
} }
func (c *testServiceClient) StreamingInputCall(ctx context.Context, opts ...rpc.CallOption) (TestService_StreamingInputCallClient, error) { func (c *testServiceClient) StreamingInputCall(ctx context.Context, opts ...grpc.CallOption) (TestService_StreamingInputCallClient, error) {
stream, err := rpc.NewClientStream(ctx, c.cc, "/grpc.testing.TestService/StreamingInputCall", opts...) stream, err := grpc.NewClientStream(ctx, c.cc, "/grpc.testing.TestService/StreamingInputCall", opts...)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -119,11 +119,11 @@ func (c *testServiceClient) StreamingInputCall(ctx context.Context, opts ...rpc.
type TestService_StreamingInputCallClient interface { type TestService_StreamingInputCallClient interface {
Send(*StreamingInputCallRequest) error Send(*StreamingInputCallRequest) error
CloseAndRecv() (*StreamingInputCallResponse, error) CloseAndRecv() (*StreamingInputCallResponse, error)
rpc.ClientStream grpc.ClientStream
} }
type testServiceStreamingInputCallClient struct { type testServiceStreamingInputCallClient struct {
rpc.ClientStream grpc.ClientStream
} }
func (x *testServiceStreamingInputCallClient) Send(m *StreamingInputCallRequest) error { func (x *testServiceStreamingInputCallClient) Send(m *StreamingInputCallRequest) error {
@ -146,8 +146,8 @@ func (x *testServiceStreamingInputCallClient) CloseAndRecv() (*StreamingInputCal
return m, fmt.Errorf("Violate gRPC client streaming protocol: no EOF after the response.") return m, fmt.Errorf("Violate gRPC client streaming protocol: no EOF after the response.")
} }
func (c *testServiceClient) FullDuplexCall(ctx context.Context, opts ...rpc.CallOption) (TestService_FullDuplexCallClient, error) { func (c *testServiceClient) FullDuplexCall(ctx context.Context, opts ...grpc.CallOption) (TestService_FullDuplexCallClient, error) {
stream, err := rpc.NewClientStream(ctx, c.cc, "/grpc.testing.TestService/FullDuplexCall", opts...) stream, err := grpc.NewClientStream(ctx, c.cc, "/grpc.testing.TestService/FullDuplexCall", opts...)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -157,11 +157,11 @@ func (c *testServiceClient) FullDuplexCall(ctx context.Context, opts ...rpc.Call
type TestService_FullDuplexCallClient interface { type TestService_FullDuplexCallClient interface {
Send(*StreamingOutputCallRequest) error Send(*StreamingOutputCallRequest) error
Recv() (*StreamingOutputCallResponse, error) Recv() (*StreamingOutputCallResponse, error)
rpc.ClientStream grpc.ClientStream
} }
type testServiceFullDuplexCallClient struct { type testServiceFullDuplexCallClient struct {
rpc.ClientStream grpc.ClientStream
} }
func (x *testServiceFullDuplexCallClient) Send(m *StreamingOutputCallRequest) error { func (x *testServiceFullDuplexCallClient) Send(m *StreamingOutputCallRequest) error {
@ -176,8 +176,8 @@ func (x *testServiceFullDuplexCallClient) Recv() (*StreamingOutputCallResponse,
return m, nil return m, nil
} }
func (c *testServiceClient) HalfDuplexCall(ctx context.Context, opts ...rpc.CallOption) (TestService_HalfDuplexCallClient, error) { func (c *testServiceClient) HalfDuplexCall(ctx context.Context, opts ...grpc.CallOption) (TestService_HalfDuplexCallClient, error) {
stream, err := rpc.NewClientStream(ctx, c.cc, "/grpc.testing.TestService/HalfDuplexCall", opts...) stream, err := grpc.NewClientStream(ctx, c.cc, "/grpc.testing.TestService/HalfDuplexCall", opts...)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -187,11 +187,11 @@ func (c *testServiceClient) HalfDuplexCall(ctx context.Context, opts ...rpc.Call
type TestService_HalfDuplexCallClient interface { type TestService_HalfDuplexCallClient interface {
Send(*StreamingOutputCallRequest) error Send(*StreamingOutputCallRequest) error
Recv() (*StreamingOutputCallResponse, error) Recv() (*StreamingOutputCallResponse, error)
rpc.ClientStream grpc.ClientStream
} }
type testServiceHalfDuplexCallClient struct { type testServiceHalfDuplexCallClient struct {
rpc.ClientStream grpc.ClientStream
} }
func (x *testServiceHalfDuplexCallClient) Send(m *StreamingOutputCallRequest) error { func (x *testServiceHalfDuplexCallClient) Send(m *StreamingOutputCallRequest) error {
@ -215,7 +215,7 @@ type TestServiceServer interface {
HalfDuplexCall(TestService_HalfDuplexCallServer) error HalfDuplexCall(TestService_HalfDuplexCallServer) error
} }
func RegisterService(s *rpc.Server, srv TestServiceServer) { func RegisterService(s *grpc.Server, srv TestServiceServer) {
s.RegisterService(&_TestService_serviceDesc, srv) s.RegisterService(&_TestService_serviceDesc, srv)
} }
@ -243,7 +243,7 @@ func _TestService_UnaryCall_Handler(srv interface{}, ctx context.Context, buf []
return out, nil return out, nil
} }
func _TestService_StreamingOutputCall_Handler(srv interface{}, stream rpc.ServerStream) error { func _TestService_StreamingOutputCall_Handler(srv interface{}, stream grpc.ServerStream) error {
m := new(StreamingOutputCallRequest) m := new(StreamingOutputCallRequest)
if err := stream.RecvProto(m); err != nil { if err := stream.RecvProto(m); err != nil {
return err return err
@ -253,29 +253,29 @@ func _TestService_StreamingOutputCall_Handler(srv interface{}, stream rpc.Server
type TestService_StreamingOutputCallServer interface { type TestService_StreamingOutputCallServer interface {
Send(*StreamingOutputCallResponse) error Send(*StreamingOutputCallResponse) error
rpc.ServerStream grpc.ServerStream
} }
type testServiceStreamingOutputCallServer struct { type testServiceStreamingOutputCallServer struct {
rpc.ServerStream grpc.ServerStream
} }
func (x *testServiceStreamingOutputCallServer) Send(m *StreamingOutputCallResponse) error { func (x *testServiceStreamingOutputCallServer) Send(m *StreamingOutputCallResponse) error {
return x.ServerStream.SendProto(m) return x.ServerStream.SendProto(m)
} }
func _TestService_StreamingInputCall_Handler(srv interface{}, stream rpc.ServerStream) error { func _TestService_StreamingInputCall_Handler(srv interface{}, stream grpc.ServerStream) error {
return srv.(TestServiceServer).StreamingInputCall(&testServiceStreamingInputCallServer{stream}) return srv.(TestServiceServer).StreamingInputCall(&testServiceStreamingInputCallServer{stream})
} }
type TestService_StreamingInputCallServer interface { type TestService_StreamingInputCallServer interface {
SendAndClose(*StreamingInputCallResponse) error SendAndClose(*StreamingInputCallResponse) error
Recv() (*StreamingInputCallRequest, error) Recv() (*StreamingInputCallRequest, error)
rpc.ServerStream grpc.ServerStream
} }
type testServiceStreamingInputCallServer struct { type testServiceStreamingInputCallServer struct {
rpc.ServerStream grpc.ServerStream
} }
func (x *testServiceStreamingInputCallServer) SendAndClose(m *StreamingInputCallResponse) error { func (x *testServiceStreamingInputCallServer) SendAndClose(m *StreamingInputCallResponse) error {
@ -293,18 +293,18 @@ func (x *testServiceStreamingInputCallServer) Recv() (*StreamingInputCallRequest
return m, nil return m, nil
} }
func _TestService_FullDuplexCall_Handler(srv interface{}, stream rpc.ServerStream) error { func _TestService_FullDuplexCall_Handler(srv interface{}, stream grpc.ServerStream) error {
return srv.(TestServiceServer).FullDuplexCall(&testServiceFullDuplexCallServer{stream}) return srv.(TestServiceServer).FullDuplexCall(&testServiceFullDuplexCallServer{stream})
} }
type TestService_FullDuplexCallServer interface { type TestService_FullDuplexCallServer interface {
Send(*StreamingOutputCallResponse) error Send(*StreamingOutputCallResponse) error
Recv() (*StreamingOutputCallRequest, error) Recv() (*StreamingOutputCallRequest, error)
rpc.ServerStream grpc.ServerStream
} }
type testServiceFullDuplexCallServer struct { type testServiceFullDuplexCallServer struct {
rpc.ServerStream grpc.ServerStream
} }
func (x *testServiceFullDuplexCallServer) Send(m *StreamingOutputCallResponse) error { func (x *testServiceFullDuplexCallServer) Send(m *StreamingOutputCallResponse) error {
@ -319,18 +319,18 @@ func (x *testServiceFullDuplexCallServer) Recv() (*StreamingOutputCallRequest, e
return m, nil return m, nil
} }
func _TestService_HalfDuplexCall_Handler(srv interface{}, stream rpc.ServerStream) error { func _TestService_HalfDuplexCall_Handler(srv interface{}, stream grpc.ServerStream) error {
return srv.(TestServiceServer).HalfDuplexCall(&testServiceHalfDuplexCallServer{stream}) return srv.(TestServiceServer).HalfDuplexCall(&testServiceHalfDuplexCallServer{stream})
} }
type TestService_HalfDuplexCallServer interface { type TestService_HalfDuplexCallServer interface {
Send(*StreamingOutputCallResponse) error Send(*StreamingOutputCallResponse) error
Recv() (*StreamingOutputCallRequest, error) Recv() (*StreamingOutputCallRequest, error)
rpc.ServerStream grpc.ServerStream
} }
type testServiceHalfDuplexCallServer struct { type testServiceHalfDuplexCallServer struct {
rpc.ServerStream grpc.ServerStream
} }
func (x *testServiceHalfDuplexCallServer) Send(m *StreamingOutputCallResponse) error { func (x *testServiceHalfDuplexCallServer) Send(m *StreamingOutputCallResponse) error {
@ -345,10 +345,10 @@ func (x *testServiceHalfDuplexCallServer) Recv() (*StreamingOutputCallRequest, e
return m, nil return m, nil
} }
var _TestService_serviceDesc = rpc.ServiceDesc{ var _TestService_serviceDesc = grpc.ServiceDesc{
ServiceName: "grpc.testing.TestService", ServiceName: "grpc.testing.TestService",
HandlerType: (*TestServiceServer)(nil), HandlerType: (*TestServiceServer)(nil),
Methods: []rpc.MethodDesc{ Methods: []grpc.MethodDesc{
{ {
MethodName: "EmptyCall", MethodName: "EmptyCall",
Handler: _TestService_EmptyCall_Handler, Handler: _TestService_EmptyCall_Handler,
@ -358,7 +358,7 @@ var _TestService_serviceDesc = rpc.ServiceDesc{
Handler: _TestService_UnaryCall_Handler, Handler: _TestService_UnaryCall_Handler,
}, },
}, },
Streams: []rpc.StreamDesc{ Streams: []grpc.StreamDesc{
{ {
StreamName: "StreamingOutputCall", StreamName: "StreamingOutputCall",
Handler: _TestService_StreamingOutputCall_Handler, Handler: _TestService_StreamingOutputCall_Handler,

View File

@ -31,7 +31,7 @@
* *
*/ */
package rpc package grpc
import ( import (
"bytes" "bytes"
@ -43,9 +43,9 @@ import (
"time" "time"
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
"github.com/grpc/grpc-go/rpc/codes" "google.golang.org/grpc/codes"
"github.com/grpc/grpc-go/rpc/metadata" "google.golang.org/grpc/metadata"
"github.com/grpc/grpc-go/rpc/transport" "google.golang.org/grpc/transport"
"golang.org/x/net/context" "golang.org/x/net/context"
) )

View File

@ -31,7 +31,7 @@
* *
*/ */
package rpc package grpc
import ( import (
"bytes" "bytes"
@ -42,8 +42,8 @@ import (
"time" "time"
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
"github.com/grpc/grpc-go/rpc/codes" "google.golang.org/grpc/codes"
"github.com/grpc/grpc-go/rpc/transport" "google.golang.org/grpc/transport"
"golang.org/x/net/context" "golang.org/x/net/context"
) )

View File

@ -31,7 +31,7 @@
* *
*/ */
package rpc package grpc
import ( import (
"fmt" "fmt"
@ -43,9 +43,9 @@ import (
"sync" "sync"
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
"github.com/grpc/grpc-go/rpc/codes" "google.golang.org/grpc/codes"
"github.com/grpc/grpc-go/rpc/metadata" "google.golang.org/grpc/metadata"
"github.com/grpc/grpc-go/rpc/transport" "google.golang.org/grpc/transport"
"golang.org/x/net/context" "golang.org/x/net/context"
) )

View File

@ -31,15 +31,15 @@
* *
*/ */
package rpc package grpc
import ( import (
"io" "io"
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
"github.com/grpc/grpc-go/rpc/codes" "google.golang.org/grpc/codes"
"github.com/grpc/grpc-go/rpc/metadata" "google.golang.org/grpc/metadata"
"github.com/grpc/grpc-go/rpc/transport" "google.golang.org/grpc/transport"
"golang.org/x/net/context" "golang.org/x/net/context"
) )

View File

@ -47,12 +47,12 @@ import (
"time" "time"
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
"github.com/grpc/grpc-go/rpc"
"github.com/grpc/grpc-go/rpc/codes"
"github.com/grpc/grpc-go/rpc/credentials"
"github.com/grpc/grpc-go/rpc/metadata"
testpb "github.com/grpc/grpc-go/rpc/test/testdata"
"golang.org/x/net/context" "golang.org/x/net/context"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/metadata"
testpb "google.golang.org/grpc/test/testdata"
) )
var ( var (
@ -68,10 +68,10 @@ type mathServer struct {
func (s *mathServer) Div(ctx context.Context, in *testpb.DivArgs) (*testpb.DivReply, error) { func (s *mathServer) Div(ctx context.Context, in *testpb.DivArgs) (*testpb.DivReply, error) {
md, ok := metadata.FromContext(ctx) md, ok := metadata.FromContext(ctx)
if ok { if ok {
if err := rpc.SendHeader(ctx, md); err != nil { if err := grpc.SendHeader(ctx, md); err != nil {
log.Fatalf("rpc.SendHeader(%v, %v) = %v, want %v", ctx, md, err, nil) log.Fatalf("grpc.SendHeader(%v, %v) = %v, want %v", ctx, md, err, nil)
} }
rpc.SetTrailer(ctx, md) grpc.SetTrailer(ctx, md)
} }
n, d := in.GetDividend(), in.GetDivisor() n, d := in.GetDividend(), in.GetDivisor()
if d == 0 { if d == 0 {
@ -148,7 +148,7 @@ func (s *mathServer) Sum(stream testpb.Math_SumServer) error {
const tlsDir = "testdata/" const tlsDir = "testdata/"
func setUp(useTLS bool, maxStream uint32) (s *rpc.Server, mc testpb.MathClient) { func setUp(useTLS bool, maxStream uint32) (s *grpc.Server, mc testpb.MathClient) {
lis, err := net.Listen("tcp", ":0") lis, err := net.Listen("tcp", ":0")
if err != nil { if err != nil {
log.Fatalf("Failed to listen: %v", err) log.Fatalf("Failed to listen: %v", err)
@ -157,7 +157,7 @@ func setUp(useTLS bool, maxStream uint32) (s *rpc.Server, mc testpb.MathClient)
if err != nil { if err != nil {
log.Fatalf("Failed to parse listener address: %v", err) log.Fatalf("Failed to parse listener address: %v", err)
} }
s = rpc.NewServer(rpc.MaxConcurrentStreams(maxStream)) s = grpc.NewServer(grpc.MaxConcurrentStreams(maxStream))
ms := &mathServer{} ms := &mathServer{}
testpb.RegisterService(s, ms) testpb.RegisterService(s, ms)
if useTLS { if useTLS {
@ -170,15 +170,15 @@ func setUp(useTLS bool, maxStream uint32) (s *rpc.Server, mc testpb.MathClient)
go s.Serve(lis) go s.Serve(lis)
} }
addr := "localhost:" + port addr := "localhost:" + port
var conn *rpc.ClientConn var conn *grpc.ClientConn
if useTLS { if useTLS {
creds, err := credentials.NewClientTLSFromFile(tlsDir+"ca.pem", "x.test.youtube.com") creds, err := credentials.NewClientTLSFromFile(tlsDir+"ca.pem", "x.test.youtube.com")
if err != nil { if err != nil {
log.Fatalf("Failed to create credentials %v", err) log.Fatalf("Failed to create credentials %v", err)
} }
conn, err = rpc.Dial(addr, rpc.WithClientTLS(creds)) conn, err = grpc.Dial(addr, grpc.WithClientTLS(creds))
} else { } else {
conn, err = rpc.Dial(addr) conn, err = grpc.Dial(addr)
} }
if err != nil { if err != nil {
log.Fatalf("Dial(%q) = %v", addr, err) log.Fatalf("Dial(%q) = %v", addr, err)
@ -194,7 +194,7 @@ func TestFailedRPC(t *testing.T) {
Dividend: proto.Int64(8), Dividend: proto.Int64(8),
Divisor: proto.Int64(0), Divisor: proto.Int64(0),
} }
expectedErr := rpc.Errorf(codes.Unknown, "math: divide by 0") expectedErr := grpc.Errorf(codes.Unknown, "math: divide by 0")
reply, rpcErr := mc.Div(context.Background(), args) reply, rpcErr := mc.Div(context.Background(), args)
if fmt.Sprint(rpcErr) != fmt.Sprint(expectedErr) { if fmt.Sprint(rpcErr) != fmt.Sprint(expectedErr) {
t.Fatalf(`mathClient.Div(_, _) = %v, %v; want <nil>, %v`, reply, rpcErr, expectedErr) t.Fatalf(`mathClient.Div(_, _) = %v, %v; want <nil>, %v`, reply, rpcErr, expectedErr)
@ -210,7 +210,7 @@ func TestMetadataUnaryRPC(t *testing.T) {
} }
ctx := metadata.NewContext(context.Background(), testMetadata) ctx := metadata.NewContext(context.Background(), testMetadata)
var header, trailer metadata.MD var header, trailer metadata.MD
_, err := mc.Div(ctx, args, rpc.Header(&header), rpc.Trailer(&trailer)) _, err := mc.Div(ctx, args, grpc.Header(&header), grpc.Trailer(&trailer))
if err != nil { if err != nil {
t.Fatalf("mathClient.Div(%v, _, _, _) = _, %v; want _, <nil>", ctx, err) t.Fatalf("mathClient.Div(%v, _, _, _) = _, %v; want _, <nil>", ctx, err)
} }
@ -277,7 +277,7 @@ func TestTimeout(t *testing.T) {
for i := 1; i <= 100; i++ { for i := 1; i <= 100; i++ {
ctx, _ := context.WithTimeout(context.Background(), time.Duration(i)*time.Microsecond) ctx, _ := context.WithTimeout(context.Background(), time.Duration(i)*time.Microsecond)
reply, err := mc.Div(ctx, args) reply, err := mc.Div(ctx, args)
if rpc.Code(err) != codes.DeadlineExceeded { if grpc.Code(err) != codes.DeadlineExceeded {
t.Fatalf(`mathClient.Div(_, _) = %v, %v; want <nil>, error code: %d`, reply, err, codes.DeadlineExceeded) t.Fatalf(`mathClient.Div(_, _) = %v, %v; want <nil>, error code: %d`, reply, err, codes.DeadlineExceeded)
} }
} }
@ -293,7 +293,7 @@ func TestCancel(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
time.AfterFunc(1*time.Millisecond, cancel) time.AfterFunc(1*time.Millisecond, cancel)
reply, err := mc.Div(ctx, args) reply, err := mc.Div(ctx, args)
if rpc.Code(err) != codes.Canceled { if grpc.Code(err) != codes.Canceled {
t.Fatalf(`mathClient.Div(_, _) = %v, %v; want <nil>, error code: %d`, reply, err, codes.Canceled) t.Fatalf(`mathClient.Div(_, _) = %v, %v; want <nil>, error code: %d`, reply, err, codes.Canceled)
} }
} }
@ -311,7 +311,7 @@ func TestBidiStreaming(t *testing.T) {
status error status error
}{ }{
{[]string{"1/1", "3/2", "2/3", "1/2"}, io.EOF}, {[]string{"1/1", "3/2", "2/3", "1/2"}, io.EOF},
{[]string{"2/5", "2/3", "3/0", "5/4"}, rpc.Errorf(codes.Unknown, "math: divide by 0")}, {[]string{"2/5", "2/3", "3/0", "5/4"}, grpc.Errorf(codes.Unknown, "math: divide by 0")},
} { } {
stream, err := mc.DivMany(context.Background()) stream, err := mc.DivMany(context.Background())
if err != nil { if err != nil {
@ -460,7 +460,7 @@ func TestExceedMaxStreamsLimit(t *testing.T) {
break break
} }
} }
if rpc.Code(err) != codes.Unavailable { if grpc.Code(err) != codes.Unavailable {
t.Fatalf("got %v, want error code %d", err, codes.Unavailable) t.Fatalf("got %v, want error code %d", err, codes.Unavailable)
} }
} }

View File

@ -35,38 +35,38 @@ package test
import ( import (
"fmt" "fmt"
"io"
"github.com/grpc/grpc-go/rpc"
context "golang.org/x/net/context"
proto "github.com/golang/protobuf/proto" proto "github.com/golang/protobuf/proto"
context "golang.org/x/net/context"
"google.golang.org/grpc"
"io"
) )
type MathClient interface { type MathClient interface {
Div(ctx context.Context, in *DivArgs, opts ...rpc.CallOption) (*DivReply, error) Div(ctx context.Context, in *DivArgs, opts ...grpc.CallOption) (*DivReply, error)
DivMany(ctx context.Context, opts ...rpc.CallOption) (Math_DivManyClient, error) DivMany(ctx context.Context, opts ...grpc.CallOption) (Math_DivManyClient, error)
Fib(ctx context.Context, m *FibArgs, opts ...rpc.CallOption) (Math_FibClient, error) Fib(ctx context.Context, m *FibArgs, opts ...grpc.CallOption) (Math_FibClient, error)
Sum(ctx context.Context, opts ...rpc.CallOption) (Math_SumClient, error) Sum(ctx context.Context, opts ...grpc.CallOption) (Math_SumClient, error)
} }
type mathClient struct { type mathClient struct {
cc *rpc.ClientConn cc *grpc.ClientConn
} }
func NewMathClient(cc *rpc.ClientConn) MathClient { func NewMathClient(cc *grpc.ClientConn) MathClient {
return &mathClient{cc} return &mathClient{cc}
} }
func (c *mathClient) Div(ctx context.Context, in *DivArgs, opts ...rpc.CallOption) (*DivReply, error) { func (c *mathClient) Div(ctx context.Context, in *DivArgs, opts ...grpc.CallOption) (*DivReply, error) {
out := new(DivReply) out := new(DivReply)
err := rpc.Invoke(ctx, "/test.Math/Div", in, out, c.cc, opts...) err := grpc.Invoke(ctx, "/test.Math/Div", in, out, c.cc, opts...)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return out, nil return out, nil
} }
func (c *mathClient) DivMany(ctx context.Context, opts ...rpc.CallOption) (Math_DivManyClient, error) { func (c *mathClient) DivMany(ctx context.Context, opts ...grpc.CallOption) (Math_DivManyClient, error) {
stream, err := rpc.NewClientStream(ctx, c.cc, "/test.Math/DivMany", opts...) stream, err := grpc.NewClientStream(ctx, c.cc, "/test.Math/DivMany", opts...)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -76,11 +76,11 @@ func (c *mathClient) DivMany(ctx context.Context, opts ...rpc.CallOption) (Math_
type Math_DivManyClient interface { type Math_DivManyClient interface {
Send(*DivArgs) error Send(*DivArgs) error
Recv() (*DivReply, error) Recv() (*DivReply, error)
rpc.ClientStream grpc.ClientStream
} }
type mathDivManyClient struct { type mathDivManyClient struct {
rpc.ClientStream grpc.ClientStream
} }
func (x *mathDivManyClient) Send(m *DivArgs) error { func (x *mathDivManyClient) Send(m *DivArgs) error {
@ -95,8 +95,8 @@ func (x *mathDivManyClient) Recv() (*DivReply, error) {
return m, nil return m, nil
} }
func (c *mathClient) Fib(ctx context.Context, m *FibArgs, opts ...rpc.CallOption) (Math_FibClient, error) { func (c *mathClient) Fib(ctx context.Context, m *FibArgs, opts ...grpc.CallOption) (Math_FibClient, error) {
stream, err := rpc.NewClientStream(ctx, c.cc, "/test.Math/Fib", opts...) stream, err := grpc.NewClientStream(ctx, c.cc, "/test.Math/Fib", opts...)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -112,11 +112,11 @@ func (c *mathClient) Fib(ctx context.Context, m *FibArgs, opts ...rpc.CallOption
type Math_FibClient interface { type Math_FibClient interface {
Recv() (*Num, error) Recv() (*Num, error)
rpc.ClientStream grpc.ClientStream
} }
type mathFibClient struct { type mathFibClient struct {
rpc.ClientStream grpc.ClientStream
} }
func (x *mathFibClient) Recv() (*Num, error) { func (x *mathFibClient) Recv() (*Num, error) {
@ -127,8 +127,8 @@ func (x *mathFibClient) Recv() (*Num, error) {
return m, nil return m, nil
} }
func (c *mathClient) Sum(ctx context.Context, opts ...rpc.CallOption) (Math_SumClient, error) { func (c *mathClient) Sum(ctx context.Context, opts ...grpc.CallOption) (Math_SumClient, error) {
stream, err := rpc.NewClientStream(ctx, c.cc, "/test.Math/Sum", opts...) stream, err := grpc.NewClientStream(ctx, c.cc, "/test.Math/Sum", opts...)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -138,11 +138,11 @@ func (c *mathClient) Sum(ctx context.Context, opts ...rpc.CallOption) (Math_SumC
type Math_SumClient interface { type Math_SumClient interface {
Send(*Num) error Send(*Num) error
CloseAndRecv() (*Num, error) CloseAndRecv() (*Num, error)
rpc.ClientStream grpc.ClientStream
} }
type mathSumClient struct { type mathSumClient struct {
rpc.ClientStream grpc.ClientStream
} }
func (x *mathSumClient) Send(m *Num) error { func (x *mathSumClient) Send(m *Num) error {
@ -165,7 +165,6 @@ func (x *mathSumClient) CloseAndRecv() (*Num, error) {
return m, fmt.Errorf("Violate gRPC client streaming protocol: no EOF after the response.") return m, fmt.Errorf("Violate gRPC client streaming protocol: no EOF after the response.")
} }
type MathServer interface { type MathServer interface {
Div(context.Context, *DivArgs) (*DivReply, error) Div(context.Context, *DivArgs) (*DivReply, error)
DivMany(Math_DivManyServer) error DivMany(Math_DivManyServer) error
@ -173,7 +172,7 @@ type MathServer interface {
Sum(Math_SumServer) error Sum(Math_SumServer) error
} }
func RegisterService(s *rpc.Server, srv MathServer) { func RegisterService(s *grpc.Server, srv MathServer) {
s.RegisterService(&_Math_serviceDesc, srv) s.RegisterService(&_Math_serviceDesc, srv)
} }
@ -189,18 +188,18 @@ func _Math_Div_Handler(srv interface{}, ctx context.Context, buf []byte) (proto.
return out, nil return out, nil
} }
func _Math_DivMany_Handler(srv interface{}, stream rpc.ServerStream) error { func _Math_DivMany_Handler(srv interface{}, stream grpc.ServerStream) error {
return srv.(MathServer).DivMany(&mathDivManyServer{stream}) return srv.(MathServer).DivMany(&mathDivManyServer{stream})
} }
type Math_DivManyServer interface { type Math_DivManyServer interface {
Send(*DivReply) error Send(*DivReply) error
Recv() (*DivArgs, error) Recv() (*DivArgs, error)
rpc.ServerStream grpc.ServerStream
} }
type mathDivManyServer struct { type mathDivManyServer struct {
rpc.ServerStream grpc.ServerStream
} }
func (x *mathDivManyServer) Send(m *DivReply) error { func (x *mathDivManyServer) Send(m *DivReply) error {
@ -215,7 +214,7 @@ func (x *mathDivManyServer) Recv() (*DivArgs, error) {
return m, nil return m, nil
} }
func _Math_Fib_Handler(srv interface{}, stream rpc.ServerStream) error { func _Math_Fib_Handler(srv interface{}, stream grpc.ServerStream) error {
m := new(FibArgs) m := new(FibArgs)
if err := stream.RecvProto(m); err != nil { if err := stream.RecvProto(m); err != nil {
return err return err
@ -225,29 +224,29 @@ func _Math_Fib_Handler(srv interface{}, stream rpc.ServerStream) error {
type Math_FibServer interface { type Math_FibServer interface {
Send(*Num) error Send(*Num) error
rpc.ServerStream grpc.ServerStream
} }
type mathFibServer struct { type mathFibServer struct {
rpc.ServerStream grpc.ServerStream
} }
func (x *mathFibServer) Send(m *Num) error { func (x *mathFibServer) Send(m *Num) error {
return x.ServerStream.SendProto(m) return x.ServerStream.SendProto(m)
} }
func _Math_Sum_Handler(srv interface{}, stream rpc.ServerStream) error { func _Math_Sum_Handler(srv interface{}, stream grpc.ServerStream) error {
return srv.(MathServer).Sum(&mathSumServer{stream}) return srv.(MathServer).Sum(&mathSumServer{stream})
} }
type Math_SumServer interface { type Math_SumServer interface {
SendAndClose(*Num) error SendAndClose(*Num) error
Recv() (*Num, error) Recv() (*Num, error)
rpc.ServerStream grpc.ServerStream
} }
type mathSumServer struct { type mathSumServer struct {
rpc.ServerStream grpc.ServerStream
} }
func (x *mathSumServer) SendAndClose(m *Num) error { func (x *mathSumServer) SendAndClose(m *Num) error {
@ -265,16 +264,16 @@ func (x *mathSumServer) Recv() (*Num, error) {
return m, nil return m, nil
} }
var _Math_serviceDesc = rpc.ServiceDesc{ var _Math_serviceDesc = grpc.ServiceDesc{
ServiceName: "test.Math", ServiceName: "test.Math",
HandlerType: (*MathServer)(nil), HandlerType: (*MathServer)(nil),
Methods: []rpc.MethodDesc{ Methods: []grpc.MethodDesc{
{ {
MethodName: "Div", MethodName: "Div",
Handler: _Math_Div_Handler, Handler: _Math_Div_Handler,
}, },
}, },
Streams: []rpc.StreamDesc{ Streams: []grpc.StreamDesc{
{ {
StreamName: "DivMany", StreamName: "DivMany",
Handler: _Math_DivMany_Handler, Handler: _Math_DivMany_Handler,
@ -289,5 +288,3 @@ var _Math_serviceDesc = rpc.ServiceDesc{
}, },
}, },
} }

View File

@ -44,9 +44,9 @@ import (
"github.com/bradfitz/http2" "github.com/bradfitz/http2"
"github.com/bradfitz/http2/hpack" "github.com/bradfitz/http2/hpack"
"github.com/grpc/grpc-go/rpc/codes" "google.golang.org/grpc/codes"
"github.com/grpc/grpc-go/rpc/credentials" "google.golang.org/grpc/credentials"
"github.com/grpc/grpc-go/rpc/metadata" "google.golang.org/grpc/metadata"
"golang.org/x/net/context" "golang.org/x/net/context"
) )

View File

@ -45,8 +45,8 @@ import (
"github.com/bradfitz/http2" "github.com/bradfitz/http2"
"github.com/bradfitz/http2/hpack" "github.com/bradfitz/http2/hpack"
"github.com/grpc/grpc-go/rpc/codes" "google.golang.org/grpc/codes"
"github.com/grpc/grpc-go/rpc/metadata" "google.golang.org/grpc/metadata"
"golang.org/x/net/context" "golang.org/x/net/context"
) )

View File

@ -41,8 +41,8 @@ import (
"github.com/bradfitz/http2" "github.com/bradfitz/http2"
"github.com/bradfitz/http2/hpack" "github.com/bradfitz/http2/hpack"
"github.com/grpc/grpc-go/rpc/codes" "google.golang.org/grpc/codes"
"github.com/grpc/grpc-go/rpc/metadata" "google.golang.org/grpc/metadata"
) )
const ( const (

View File

@ -44,9 +44,9 @@ import (
"net" "net"
"sync" "sync"
"github.com/grpc/grpc-go/rpc/codes" "google.golang.org/grpc/codes"
"github.com/grpc/grpc-go/rpc/credentials" "google.golang.org/grpc/credentials"
"github.com/grpc/grpc-go/rpc/metadata" "google.golang.org/grpc/metadata"
"golang.org/x/net/context" "golang.org/x/net/context"
) )

View File

@ -45,8 +45,8 @@ import (
"testing" "testing"
"time" "time"
"github.com/grpc/grpc-go/rpc/codes" "google.golang.org/grpc/codes"
"github.com/grpc/grpc-go/rpc/credentials" "google.golang.org/grpc/credentials"
"golang.org/x/net/context" "golang.org/x/net/context"
) )