diff --git a/Makefile b/Makefile index fbde89d7cd5..92da377f8ea 100644 --- a/Makefile +++ b/Makefile @@ -3,9 +3,9 @@ GO_PLUGIN=bin/protoc-gen-go GO_PLUGIN_PKG=github.com/golang/protobuf/protoc-gen-go GATEWAY_PLUGIN=bin/protoc-gen-grpc-gateway GATEWAY_PLUGIN_PKG=$(PKG)/protoc-gen-grpc-gateway -GATEWAY_PLUGIN_SRC= internal/doc.go \ - internal/name.go \ - internal/pattern.go \ +GATEWAY_PLUGIN_SRC= utilities/doc.go \ + utilities/name.go \ + utilities/pattern.go \ protoc-gen-grpc-gateway/descriptor/registry.go \ protoc-gen-grpc-gateway/descriptor/services.go \ protoc-gen-grpc-gateway/descriptor/types.go \ @@ -21,8 +21,8 @@ OPTIONS_PROTO=$(GOOGLEAPIS_DIR)/google/api/annotations.proto $(GOOGLEAPIS_DIR)/g OPTIONS_GO=$(OPTIONS_PROTO:.proto=.pb.go) PKGMAP=Mgoogle/protobuf/descriptor.proto=$(GO_PLUGIN_PKG)/descriptor,Mexamples/sub/message.proto=$(PKG)/examples/sub -EXAMPLES=examples/echo_service.proto \ - examples/a_bit_of_everything.proto +EXAMPLES=examples/examplepb/echo_service.proto \ + examples/examplepb/a_bit_of_everything.proto EXAMPLE_SVCSRCS=$(EXAMPLES:.proto=.pb.go) EXAMPLE_GWSRCS=$(EXAMPLES:.proto=.pb.gw.go) EXAMPLE_DEPS=examples/sub/message.proto diff --git a/examples/a_bit_of_everything.pb.go b/examples/examplepb/a_bit_of_everything.pb.go similarity index 89% rename from examples/a_bit_of_everything.pb.go rename to examples/examplepb/a_bit_of_everything.pb.go index f4b1da3c0f6..5c9f422c36e 100644 --- a/examples/a_bit_of_everything.pb.go +++ b/examples/examplepb/a_bit_of_everything.pb.go @@ -1,12 +1,12 @@ // Code generated by protoc-gen-go. -// source: examples/a_bit_of_everything.proto +// source: examples/examplepb/a_bit_of_everything.proto // DO NOT EDIT! -package main +package examplepb import proto "github.com/golang/protobuf/proto" -// discarding unused import google_api1 "google/api/annotations.pb" +// discarding unused import google_api1 "google/api" import gengo_grpc_gateway_examples_sub "github.com/gengo/grpc-gateway/examples/sub" import ( @@ -77,9 +77,6 @@ func (m *IdMessage) Reset() { *m = IdMessage{} } func (m *IdMessage) String() string { return proto.CompactTextString(m) } func (*IdMessage) ProtoMessage() {} -func init() { -} - // Client API for ABitOfEverythingService service type ABitOfEverythingServiceClient interface { @@ -104,7 +101,7 @@ func NewABitOfEverythingServiceClient(cc *grpc.ClientConn) ABitOfEverythingServi func (c *aBitOfEverythingServiceClient) Create(ctx context.Context, in *ABitOfEverything, opts ...grpc.CallOption) (*ABitOfEverything, error) { out := new(ABitOfEverything) - err := grpc.Invoke(ctx, "/gengo.grpc.gateway.examples.ABitOfEverythingService/Create", in, out, c.cc, opts...) + err := grpc.Invoke(ctx, "/gengo.grpc.gateway.examples.examplepb.ABitOfEverythingService/Create", in, out, c.cc, opts...) if err != nil { return nil, err } @@ -113,7 +110,7 @@ func (c *aBitOfEverythingServiceClient) Create(ctx context.Context, in *ABitOfEv func (c *aBitOfEverythingServiceClient) CreateBody(ctx context.Context, in *ABitOfEverything, opts ...grpc.CallOption) (*ABitOfEverything, error) { out := new(ABitOfEverything) - err := grpc.Invoke(ctx, "/gengo.grpc.gateway.examples.ABitOfEverythingService/CreateBody", in, out, c.cc, opts...) + err := grpc.Invoke(ctx, "/gengo.grpc.gateway.examples.examplepb.ABitOfEverythingService/CreateBody", in, out, c.cc, opts...) if err != nil { return nil, err } @@ -121,7 +118,7 @@ func (c *aBitOfEverythingServiceClient) CreateBody(ctx context.Context, in *ABit } func (c *aBitOfEverythingServiceClient) BulkCreate(ctx context.Context, opts ...grpc.CallOption) (ABitOfEverythingService_BulkCreateClient, error) { - stream, err := grpc.NewClientStream(ctx, &_ABitOfEverythingService_serviceDesc.Streams[0], c.cc, "/gengo.grpc.gateway.examples.ABitOfEverythingService/BulkCreate", opts...) + stream, err := grpc.NewClientStream(ctx, &_ABitOfEverythingService_serviceDesc.Streams[0], c.cc, "/gengo.grpc.gateway.examples.examplepb.ABitOfEverythingService/BulkCreate", opts...) if err != nil { return nil, err } @@ -156,7 +153,7 @@ func (x *aBitOfEverythingServiceBulkCreateClient) CloseAndRecv() (*EmptyMessage, func (c *aBitOfEverythingServiceClient) Lookup(ctx context.Context, in *IdMessage, opts ...grpc.CallOption) (*ABitOfEverything, error) { out := new(ABitOfEverything) - err := grpc.Invoke(ctx, "/gengo.grpc.gateway.examples.ABitOfEverythingService/Lookup", in, out, c.cc, opts...) + err := grpc.Invoke(ctx, "/gengo.grpc.gateway.examples.examplepb.ABitOfEverythingService/Lookup", in, out, c.cc, opts...) if err != nil { return nil, err } @@ -164,7 +161,7 @@ func (c *aBitOfEverythingServiceClient) Lookup(ctx context.Context, in *IdMessag } func (c *aBitOfEverythingServiceClient) List(ctx context.Context, in *EmptyMessage, opts ...grpc.CallOption) (ABitOfEverythingService_ListClient, error) { - stream, err := grpc.NewClientStream(ctx, &_ABitOfEverythingService_serviceDesc.Streams[1], c.cc, "/gengo.grpc.gateway.examples.ABitOfEverythingService/List", opts...) + stream, err := grpc.NewClientStream(ctx, &_ABitOfEverythingService_serviceDesc.Streams[1], c.cc, "/gengo.grpc.gateway.examples.examplepb.ABitOfEverythingService/List", opts...) if err != nil { return nil, err } @@ -197,7 +194,7 @@ func (x *aBitOfEverythingServiceListClient) Recv() (*ABitOfEverything, error) { func (c *aBitOfEverythingServiceClient) Update(ctx context.Context, in *ABitOfEverything, opts ...grpc.CallOption) (*EmptyMessage, error) { out := new(EmptyMessage) - err := grpc.Invoke(ctx, "/gengo.grpc.gateway.examples.ABitOfEverythingService/Update", in, out, c.cc, opts...) + err := grpc.Invoke(ctx, "/gengo.grpc.gateway.examples.examplepb.ABitOfEverythingService/Update", in, out, c.cc, opts...) if err != nil { return nil, err } @@ -206,7 +203,7 @@ func (c *aBitOfEverythingServiceClient) Update(ctx context.Context, in *ABitOfEv func (c *aBitOfEverythingServiceClient) Delete(ctx context.Context, in *IdMessage, opts ...grpc.CallOption) (*EmptyMessage, error) { out := new(EmptyMessage) - err := grpc.Invoke(ctx, "/gengo.grpc.gateway.examples.ABitOfEverythingService/Delete", in, out, c.cc, opts...) + err := grpc.Invoke(ctx, "/gengo.grpc.gateway.examples.examplepb.ABitOfEverythingService/Delete", in, out, c.cc, opts...) if err != nil { return nil, err } @@ -215,7 +212,7 @@ func (c *aBitOfEverythingServiceClient) Delete(ctx context.Context, in *IdMessag func (c *aBitOfEverythingServiceClient) Echo(ctx context.Context, in *gengo_grpc_gateway_examples_sub.StringMessage, opts ...grpc.CallOption) (*gengo_grpc_gateway_examples_sub.StringMessage, error) { out := new(gengo_grpc_gateway_examples_sub.StringMessage) - err := grpc.Invoke(ctx, "/gengo.grpc.gateway.examples.ABitOfEverythingService/Echo", in, out, c.cc, opts...) + err := grpc.Invoke(ctx, "/gengo.grpc.gateway.examples.examplepb.ABitOfEverythingService/Echo", in, out, c.cc, opts...) if err != nil { return nil, err } @@ -223,7 +220,7 @@ func (c *aBitOfEverythingServiceClient) Echo(ctx context.Context, in *gengo_grpc } func (c *aBitOfEverythingServiceClient) BulkEcho(ctx context.Context, opts ...grpc.CallOption) (ABitOfEverythingService_BulkEchoClient, error) { - stream, err := grpc.NewClientStream(ctx, &_ABitOfEverythingService_serviceDesc.Streams[2], c.cc, "/gengo.grpc.gateway.examples.ABitOfEverythingService/BulkEcho", opts...) + stream, err := grpc.NewClientStream(ctx, &_ABitOfEverythingService_serviceDesc.Streams[2], c.cc, "/gengo.grpc.gateway.examples.examplepb.ABitOfEverythingService/BulkEcho", opts...) if err != nil { return nil, err } @@ -271,9 +268,9 @@ func RegisterABitOfEverythingServiceServer(s *grpc.Server, srv ABitOfEverythingS s.RegisterService(&_ABitOfEverythingService_serviceDesc, srv) } -func _ABitOfEverythingService_Create_Handler(srv interface{}, ctx context.Context, buf []byte) (interface{}, error) { +func _ABitOfEverythingService_Create_Handler(srv interface{}, ctx context.Context, codec grpc.Codec, buf []byte) (interface{}, error) { in := new(ABitOfEverything) - if err := proto.Unmarshal(buf, in); err != nil { + if err := codec.Unmarshal(buf, in); err != nil { return nil, err } out, err := srv.(ABitOfEverythingServiceServer).Create(ctx, in) @@ -283,9 +280,9 @@ func _ABitOfEverythingService_Create_Handler(srv interface{}, ctx context.Contex return out, nil } -func _ABitOfEverythingService_CreateBody_Handler(srv interface{}, ctx context.Context, buf []byte) (interface{}, error) { +func _ABitOfEverythingService_CreateBody_Handler(srv interface{}, ctx context.Context, codec grpc.Codec, buf []byte) (interface{}, error) { in := new(ABitOfEverything) - if err := proto.Unmarshal(buf, in); err != nil { + if err := codec.Unmarshal(buf, in); err != nil { return nil, err } out, err := srv.(ABitOfEverythingServiceServer).CreateBody(ctx, in) @@ -321,9 +318,9 @@ func (x *aBitOfEverythingServiceBulkCreateServer) Recv() (*ABitOfEverything, err return m, nil } -func _ABitOfEverythingService_Lookup_Handler(srv interface{}, ctx context.Context, buf []byte) (interface{}, error) { +func _ABitOfEverythingService_Lookup_Handler(srv interface{}, ctx context.Context, codec grpc.Codec, buf []byte) (interface{}, error) { in := new(IdMessage) - if err := proto.Unmarshal(buf, in); err != nil { + if err := codec.Unmarshal(buf, in); err != nil { return nil, err } out, err := srv.(ABitOfEverythingServiceServer).Lookup(ctx, in) @@ -354,9 +351,9 @@ func (x *aBitOfEverythingServiceListServer) Send(m *ABitOfEverything) error { return x.ServerStream.SendMsg(m) } -func _ABitOfEverythingService_Update_Handler(srv interface{}, ctx context.Context, buf []byte) (interface{}, error) { +func _ABitOfEverythingService_Update_Handler(srv interface{}, ctx context.Context, codec grpc.Codec, buf []byte) (interface{}, error) { in := new(ABitOfEverything) - if err := proto.Unmarshal(buf, in); err != nil { + if err := codec.Unmarshal(buf, in); err != nil { return nil, err } out, err := srv.(ABitOfEverythingServiceServer).Update(ctx, in) @@ -366,9 +363,9 @@ func _ABitOfEverythingService_Update_Handler(srv interface{}, ctx context.Contex return out, nil } -func _ABitOfEverythingService_Delete_Handler(srv interface{}, ctx context.Context, buf []byte) (interface{}, error) { +func _ABitOfEverythingService_Delete_Handler(srv interface{}, ctx context.Context, codec grpc.Codec, buf []byte) (interface{}, error) { in := new(IdMessage) - if err := proto.Unmarshal(buf, in); err != nil { + if err := codec.Unmarshal(buf, in); err != nil { return nil, err } out, err := srv.(ABitOfEverythingServiceServer).Delete(ctx, in) @@ -378,9 +375,9 @@ func _ABitOfEverythingService_Delete_Handler(srv interface{}, ctx context.Contex return out, nil } -func _ABitOfEverythingService_Echo_Handler(srv interface{}, ctx context.Context, buf []byte) (interface{}, error) { +func _ABitOfEverythingService_Echo_Handler(srv interface{}, ctx context.Context, codec grpc.Codec, buf []byte) (interface{}, error) { in := new(gengo_grpc_gateway_examples_sub.StringMessage) - if err := proto.Unmarshal(buf, in); err != nil { + if err := codec.Unmarshal(buf, in); err != nil { return nil, err } out, err := srv.(ABitOfEverythingServiceServer).Echo(ctx, in) @@ -417,7 +414,7 @@ func (x *aBitOfEverythingServiceBulkEchoServer) Recv() (*gengo_grpc_gateway_exam } var _ABitOfEverythingService_serviceDesc = grpc.ServiceDesc{ - ServiceName: "gengo.grpc.gateway.examples.ABitOfEverythingService", + ServiceName: "gengo.grpc.gateway.examples.examplepb.ABitOfEverythingService", HandlerType: (*ABitOfEverythingServiceServer)(nil), Methods: []grpc.MethodDesc{ { diff --git a/examples/a_bit_of_everything.pb.gw.go b/examples/examplepb/a_bit_of_everything.pb.gw.go similarity index 95% rename from examples/a_bit_of_everything.pb.gw.go rename to examples/examplepb/a_bit_of_everything.pb.gw.go index 39495a8d128..b2d9f1afa66 100644 --- a/examples/a_bit_of_everything.pb.gw.go +++ b/examples/examplepb/a_bit_of_everything.pb.gw.go @@ -1,13 +1,13 @@ // Code generated by protoc-gen-grpc-gateway -// source: examples/a_bit_of_everything.proto +// source: examples/examplepb/a_bit_of_everything.proto // DO NOT EDIT! /* -Package main is a reverse proxy. +Package examplepb is a reverse proxy. It translates gRPC into RESTful JSON APIs. */ -package main +package examplepb import ( "encoding/json" @@ -15,8 +15,8 @@ import ( "net/http" "github.com/gengo/grpc-gateway/examples/sub" - "github.com/gengo/grpc-gateway/internal" "github.com/gengo/grpc-gateway/runtime" + "github.com/gengo/grpc-gateway/utilities" "github.com/golang/glog" "github.com/golang/protobuf/proto" "golang.org/x/net/context" @@ -28,10 +28,10 @@ var _ codes.Code var _ io.Reader var _ = runtime.String var _ = json.Marshal -var _ = internal.PascalFromSnake +var _ = utilities.PascalFromSnake var ( - filter_ABitOfEverythingService_Create_0 = &internal.DoubleArray{Encoding: map[string]int{"float_value": 0, "double_value": 1, "int64_value": 2, "uint64_value": 3, "int32_value": 4, "fixed64_value": 5, "fixed32_value": 6, "bool_value": 7, "string_value": 8, "uint32_value": 9, "sfixed32_value": 10, "sfixed64_value": 11, "sint32_value": 12, "sint64_value": 13}, Base: []int{1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, Check: []int{0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}} + filter_ABitOfEverythingService_Create_0 = &utilities.DoubleArray{Encoding: map[string]int{"float_value": 0, "double_value": 1, "int64_value": 2, "uint64_value": 3, "int32_value": 4, "fixed64_value": 5, "fixed32_value": 6, "bool_value": 7, "string_value": 8, "uint32_value": 9, "sfixed32_value": 10, "sfixed64_value": 11, "sint32_value": 12, "sint64_value": 13}, Base: []int{1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, Check: []int{0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}} ) func request_ABitOfEverythingService_Create_0(ctx context.Context, client ABitOfEverythingServiceClient, req *http.Request, pathParams map[string]string) (msg proto.Message, err error) { @@ -44,7 +44,9 @@ func request_ABitOfEverythingService_Create_0(ctx context.Context, client ABitOf if !ok { return nil, grpc.Errorf(codes.InvalidArgument, "missing parameter %s", "float_value") } + protoReq.FloatValue, err = runtime.Float32(val) + if err != nil { return nil, err } @@ -53,7 +55,9 @@ func request_ABitOfEverythingService_Create_0(ctx context.Context, client ABitOf if !ok { return nil, grpc.Errorf(codes.InvalidArgument, "missing parameter %s", "double_value") } + protoReq.DoubleValue, err = runtime.Float64(val) + if err != nil { return nil, err } @@ -62,7 +66,9 @@ func request_ABitOfEverythingService_Create_0(ctx context.Context, client ABitOf if !ok { return nil, grpc.Errorf(codes.InvalidArgument, "missing parameter %s", "int64_value") } + protoReq.Int64Value, err = runtime.Int64(val) + if err != nil { return nil, err } @@ -71,7 +77,9 @@ func request_ABitOfEverythingService_Create_0(ctx context.Context, client ABitOf if !ok { return nil, grpc.Errorf(codes.InvalidArgument, "missing parameter %s", "uint64_value") } + protoReq.Uint64Value, err = runtime.Uint64(val) + if err != nil { return nil, err } @@ -80,7 +88,9 @@ func request_ABitOfEverythingService_Create_0(ctx context.Context, client ABitOf if !ok { return nil, grpc.Errorf(codes.InvalidArgument, "missing parameter %s", "int32_value") } + protoReq.Int32Value, err = runtime.Int32(val) + if err != nil { return nil, err } @@ -89,7 +99,9 @@ func request_ABitOfEverythingService_Create_0(ctx context.Context, client ABitOf if !ok { return nil, grpc.Errorf(codes.InvalidArgument, "missing parameter %s", "fixed64_value") } + protoReq.Fixed64Value, err = runtime.Uint64(val) + if err != nil { return nil, err } @@ -98,7 +110,9 @@ func request_ABitOfEverythingService_Create_0(ctx context.Context, client ABitOf if !ok { return nil, grpc.Errorf(codes.InvalidArgument, "missing parameter %s", "fixed32_value") } + protoReq.Fixed32Value, err = runtime.Uint32(val) + if err != nil { return nil, err } @@ -107,7 +121,9 @@ func request_ABitOfEverythingService_Create_0(ctx context.Context, client ABitOf if !ok { return nil, grpc.Errorf(codes.InvalidArgument, "missing parameter %s", "bool_value") } + protoReq.BoolValue, err = runtime.Bool(val) + if err != nil { return nil, err } @@ -116,7 +132,9 @@ func request_ABitOfEverythingService_Create_0(ctx context.Context, client ABitOf if !ok { return nil, grpc.Errorf(codes.InvalidArgument, "missing parameter %s", "string_value") } + protoReq.StringValue, err = runtime.String(val) + if err != nil { return nil, err } @@ -125,7 +143,9 @@ func request_ABitOfEverythingService_Create_0(ctx context.Context, client ABitOf if !ok { return nil, grpc.Errorf(codes.InvalidArgument, "missing parameter %s", "uint32_value") } + protoReq.Uint32Value, err = runtime.Uint32(val) + if err != nil { return nil, err } @@ -134,7 +154,9 @@ func request_ABitOfEverythingService_Create_0(ctx context.Context, client ABitOf if !ok { return nil, grpc.Errorf(codes.InvalidArgument, "missing parameter %s", "sfixed32_value") } + protoReq.Sfixed32Value, err = runtime.Int32(val) + if err != nil { return nil, err } @@ -143,7 +165,9 @@ func request_ABitOfEverythingService_Create_0(ctx context.Context, client ABitOf if !ok { return nil, grpc.Errorf(codes.InvalidArgument, "missing parameter %s", "sfixed64_value") } + protoReq.Sfixed64Value, err = runtime.Int64(val) + if err != nil { return nil, err } @@ -152,7 +176,9 @@ func request_ABitOfEverythingService_Create_0(ctx context.Context, client ABitOf if !ok { return nil, grpc.Errorf(codes.InvalidArgument, "missing parameter %s", "sint32_value") } + protoReq.Sint32Value, err = runtime.Int32(val) + if err != nil { return nil, err } @@ -161,7 +187,9 @@ func request_ABitOfEverythingService_Create_0(ctx context.Context, client ABitOf if !ok { return nil, grpc.Errorf(codes.InvalidArgument, "missing parameter %s", "sint64_value") } + protoReq.Sint64Value, err = runtime.Int64(val) + if err != nil { return nil, err } @@ -220,7 +248,9 @@ func request_ABitOfEverythingService_Lookup_0(ctx context.Context, client ABitOf if !ok { return nil, grpc.Errorf(codes.InvalidArgument, "missing parameter %s", "uuid") } + protoReq.Uuid, err = runtime.String(val) + if err != nil { return nil, err } @@ -248,7 +278,9 @@ func request_ABitOfEverythingService_Update_0(ctx context.Context, client ABitOf if !ok { return nil, grpc.Errorf(codes.InvalidArgument, "missing parameter %s", "uuid") } + protoReq.Uuid, err = runtime.String(val) + if err != nil { return nil, err } @@ -266,7 +298,9 @@ func request_ABitOfEverythingService_Delete_0(ctx context.Context, client ABitOf if !ok { return nil, grpc.Errorf(codes.InvalidArgument, "missing parameter %s", "uuid") } + protoReq.Uuid, err = runtime.String(val) + if err != nil { return nil, err } @@ -284,7 +318,9 @@ func request_ABitOfEverythingService_Echo_0(ctx context.Context, client ABitOfEv if !ok { return nil, grpc.Errorf(codes.InvalidArgument, "missing parameter %s", "value") } + protoReq.Value, err = runtime.StringP(val) + if err != nil { return nil, err } @@ -303,7 +339,7 @@ func request_ABitOfEverythingService_Echo_1(ctx context.Context, client ABitOfEv } var ( - filter_ABitOfEverythingService_Echo_2 = &internal.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} + filter_ABitOfEverythingService_Echo_2 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} ) func request_ABitOfEverythingService_Echo_2(ctx context.Context, client ABitOfEverythingServiceClient, req *http.Request, pathParams map[string]string) (msg proto.Message, err error) { diff --git a/examples/a_bit_of_everything.proto b/examples/examplepb/a_bit_of_everything.proto similarity index 97% rename from examples/a_bit_of_everything.proto rename to examples/examplepb/a_bit_of_everything.proto index c4cf1ee8b32..9586355dce2 100644 --- a/examples/a_bit_of_everything.proto +++ b/examples/examplepb/a_bit_of_everything.proto @@ -1,6 +1,6 @@ syntax = "proto3"; -option go_package = "main"; -package gengo.grpc.gateway.examples; +option go_package = "examplepb"; +package gengo.grpc.gateway.examples.examplepb; import "google/api/annotations.proto"; import "examples/sub/message.proto"; diff --git a/examples/echo_service.pb.go b/examples/examplepb/echo_service.pb.go similarity index 77% rename from examples/echo_service.pb.go rename to examples/examplepb/echo_service.pb.go index 39b3d530fef..daf0fac99d9 100644 --- a/examples/echo_service.pb.go +++ b/examples/examplepb/echo_service.pb.go @@ -1,22 +1,22 @@ // Code generated by protoc-gen-go. -// source: examples/echo_service.proto +// source: examples/examplepb/echo_service.proto // DO NOT EDIT! /* -Package main is a generated protocol buffer package. +Package examplepb is a generated protocol buffer package. It is generated from these files: - examples/echo_service.proto - examples/a_bit_of_everything.proto + examples/examplepb/echo_service.proto + examples/examplepb/a_bit_of_everything.proto It has these top-level messages: SimpleMessage */ -package main +package examplepb import proto "github.com/golang/protobuf/proto" -// discarding unused import google_api1 "google/api/annotations.pb" +// discarding unused import google_api1 "google/api" import ( context "golang.org/x/net/context" @@ -38,9 +38,6 @@ func (m *SimpleMessage) Reset() { *m = SimpleMessage{} } func (m *SimpleMessage) String() string { return proto.CompactTextString(m) } func (*SimpleMessage) ProtoMessage() {} -func init() { -} - // Client API for EchoService service type EchoServiceClient interface { @@ -58,7 +55,7 @@ func NewEchoServiceClient(cc *grpc.ClientConn) EchoServiceClient { func (c *echoServiceClient) Echo(ctx context.Context, in *SimpleMessage, opts ...grpc.CallOption) (*SimpleMessage, error) { out := new(SimpleMessage) - err := grpc.Invoke(ctx, "/gengo.grpc.gateway.example.EchoService/Echo", in, out, c.cc, opts...) + err := grpc.Invoke(ctx, "/gengo.grpc.gateway.examples.examplepb.EchoService/Echo", in, out, c.cc, opts...) if err != nil { return nil, err } @@ -67,7 +64,7 @@ func (c *echoServiceClient) Echo(ctx context.Context, in *SimpleMessage, opts .. func (c *echoServiceClient) EchoBody(ctx context.Context, in *SimpleMessage, opts ...grpc.CallOption) (*SimpleMessage, error) { out := new(SimpleMessage) - err := grpc.Invoke(ctx, "/gengo.grpc.gateway.example.EchoService/EchoBody", in, out, c.cc, opts...) + err := grpc.Invoke(ctx, "/gengo.grpc.gateway.examples.examplepb.EchoService/EchoBody", in, out, c.cc, opts...) if err != nil { return nil, err } @@ -85,9 +82,9 @@ func RegisterEchoServiceServer(s *grpc.Server, srv EchoServiceServer) { s.RegisterService(&_EchoService_serviceDesc, srv) } -func _EchoService_Echo_Handler(srv interface{}, ctx context.Context, buf []byte) (interface{}, error) { +func _EchoService_Echo_Handler(srv interface{}, ctx context.Context, codec grpc.Codec, buf []byte) (interface{}, error) { in := new(SimpleMessage) - if err := proto.Unmarshal(buf, in); err != nil { + if err := codec.Unmarshal(buf, in); err != nil { return nil, err } out, err := srv.(EchoServiceServer).Echo(ctx, in) @@ -97,9 +94,9 @@ func _EchoService_Echo_Handler(srv interface{}, ctx context.Context, buf []byte) return out, nil } -func _EchoService_EchoBody_Handler(srv interface{}, ctx context.Context, buf []byte) (interface{}, error) { +func _EchoService_EchoBody_Handler(srv interface{}, ctx context.Context, codec grpc.Codec, buf []byte) (interface{}, error) { in := new(SimpleMessage) - if err := proto.Unmarshal(buf, in); err != nil { + if err := codec.Unmarshal(buf, in); err != nil { return nil, err } out, err := srv.(EchoServiceServer).EchoBody(ctx, in) @@ -110,7 +107,7 @@ func _EchoService_EchoBody_Handler(srv interface{}, ctx context.Context, buf []b } var _EchoService_serviceDesc = grpc.ServiceDesc{ - ServiceName: "gengo.grpc.gateway.example.EchoService", + ServiceName: "gengo.grpc.gateway.examples.examplepb.EchoService", HandlerType: (*EchoServiceServer)(nil), Methods: []grpc.MethodDesc{ { diff --git a/examples/echo_service.pb.gw.go b/examples/examplepb/echo_service.pb.gw.go similarity index 94% rename from examples/echo_service.pb.gw.go rename to examples/examplepb/echo_service.pb.gw.go index 5f1561803f2..ec866879832 100644 --- a/examples/echo_service.pb.gw.go +++ b/examples/examplepb/echo_service.pb.gw.go @@ -1,21 +1,21 @@ // Code generated by protoc-gen-grpc-gateway -// source: examples/echo_service.proto +// source: examples/examplepb/echo_service.proto // DO NOT EDIT! /* -Package main is a reverse proxy. +Package examplepb is a reverse proxy. It translates gRPC into RESTful JSON APIs. */ -package main +package examplepb import ( "encoding/json" "io" "net/http" - "github.com/gengo/grpc-gateway/internal" "github.com/gengo/grpc-gateway/runtime" + "github.com/gengo/grpc-gateway/utilities" "github.com/golang/glog" "github.com/golang/protobuf/proto" "golang.org/x/net/context" @@ -27,7 +27,7 @@ var _ codes.Code var _ io.Reader var _ = runtime.String var _ = json.Marshal -var _ = internal.PascalFromSnake +var _ = utilities.PascalFromSnake func request_EchoService_Echo_0(ctx context.Context, client EchoServiceClient, req *http.Request, pathParams map[string]string) (msg proto.Message, err error) { var protoReq SimpleMessage @@ -39,7 +39,9 @@ func request_EchoService_Echo_0(ctx context.Context, client EchoServiceClient, r if !ok { return nil, grpc.Errorf(codes.InvalidArgument, "missing parameter %s", "id") } + protoReq.Id, err = runtime.String(val) + if err != nil { return nil, err } diff --git a/examples/echo_service.proto b/examples/examplepb/echo_service.proto similarity index 82% rename from examples/echo_service.proto rename to examples/examplepb/echo_service.proto index f9d5d762847..5e44b2827c6 100644 --- a/examples/echo_service.proto +++ b/examples/examplepb/echo_service.proto @@ -1,6 +1,6 @@ syntax = "proto3"; -option go_package = "main"; -package gengo.grpc.gateway.example; +option go_package = "examplepb"; +package gengo.grpc.gateway.examples.examplepb; import "google/api/annotations.proto"; diff --git a/examples/integration_test.go b/examples/integration_test.go index 65fddc9907b..4382351ab27 100644 --- a/examples/integration_test.go +++ b/examples/integration_test.go @@ -1,4 +1,4 @@ -package main_test +package main import ( "bytes" @@ -12,7 +12,7 @@ import ( "testing" "time" - gw "github.com/gengo/grpc-gateway/examples" + gw "github.com/gengo/grpc-gateway/examples/examplepb" server "github.com/gengo/grpc-gateway/examples/server" sub "github.com/gengo/grpc-gateway/examples/sub" ) @@ -30,7 +30,7 @@ func TestIntegration(t *testing.T) { } }() go func() { - if err := gw.Run(); err != nil { + if err := Run(); err != nil { t.Errorf("gw.Run() failed with %v; want success", err) return } diff --git a/examples/main.go b/examples/main.go index 6836c9b21be..0d4b6f86523 100644 --- a/examples/main.go +++ b/examples/main.go @@ -4,6 +4,7 @@ import ( "flag" "net/http" + "github.com/gengo/grpc-gateway/examples/examplepb" "github.com/gengo/grpc-gateway/runtime" "github.com/golang/glog" "golang.org/x/net/context" @@ -20,11 +21,11 @@ func Run() error { defer cancel() mux := runtime.NewServeMux() - err := RegisterEchoServiceHandlerFromEndpoint(ctx, mux, *echoEndpoint) + err := examplepb.RegisterEchoServiceHandlerFromEndpoint(ctx, mux, *echoEndpoint) if err != nil { return err } - err = RegisterABitOfEverythingServiceHandlerFromEndpoint(ctx, mux, *abeEndpoint) + err = examplepb.RegisterABitOfEverythingServiceHandlerFromEndpoint(ctx, mux, *abeEndpoint) if err != nil { return err } diff --git a/examples/server/main.go b/examples/server/main.go index 2e9463b31a4..a48ef60dcaa 100644 --- a/examples/server/main.go +++ b/examples/server/main.go @@ -7,7 +7,7 @@ import ( "net" "sync" - examples "github.com/gengo/grpc-gateway/examples" + examples "github.com/gengo/grpc-gateway/examples/examplepb" sub "github.com/gengo/grpc-gateway/examples/sub" "github.com/golang/glog" "github.com/rogpeppe/fastuuid" diff --git a/examples/sub/message.pb.go b/examples/sub/message.pb.go index 9ad656dfaed..04be0cc748e 100644 --- a/examples/sub/message.pb.go +++ b/examples/sub/message.pb.go @@ -35,6 +35,3 @@ func (m *StringMessage) GetValue() string { } return "" } - -func init() { -} diff --git a/internal/doc.go b/internal/doc.go deleted file mode 100644 index 0860ea062cf..00000000000 --- a/internal/doc.go +++ /dev/null @@ -1,2 +0,0 @@ -// Package internal provides members for internal use in grpc-gateway. -package internal diff --git a/protoc-gen-grpc-gateway/descriptor/types.go b/protoc-gen-grpc-gateway/descriptor/types.go index e9fb6e1b9d3..b3d155eb566 100644 --- a/protoc-gen-grpc-gateway/descriptor/types.go +++ b/protoc-gen-grpc-gateway/descriptor/types.go @@ -4,7 +4,7 @@ import ( "fmt" "strings" - "github.com/gengo/grpc-gateway/internal" + "github.com/gengo/grpc-gateway/utilities" "github.com/gengo/grpc-gateway/protoc-gen-grpc-gateway/httprule" descriptor "github.com/golang/protobuf/protoc-gen-go/descriptor" ) @@ -233,15 +233,15 @@ type FieldPathComponent struct { // RHS returns a right-hand-side expression in go for this field. func (c FieldPathComponent) RHS() string { - return internal.PascalFromSnake(c.Name) + return utilities.PascalFromSnake(c.Name) } // LHS returns a left-hand-side expression in go for this field. func (c FieldPathComponent) LHS() string { if c.Target.Message.File.proto2() { - return fmt.Sprintf("Get%s()", internal.PascalFromSnake(c.Name)) + return fmt.Sprintf("Get%s()", utilities.PascalFromSnake(c.Name)) } - return internal.PascalFromSnake(c.Name) + return utilities.PascalFromSnake(c.Name) } var ( diff --git a/protoc-gen-grpc-gateway/gengateway/generator.go b/protoc-gen-grpc-gateway/gengateway/generator.go index 6d752440b4a..8a9927dc8f8 100644 --- a/protoc-gen-grpc-gateway/gengateway/generator.go +++ b/protoc-gen-grpc-gateway/gengateway/generator.go @@ -31,7 +31,7 @@ func New(reg *descriptor.Registry) *generator { "io", "net/http", "github.com/gengo/grpc-gateway/runtime", - "github.com/gengo/grpc-gateway/internal", + "github.com/gengo/grpc-gateway/utilities", "github.com/golang/glog", "github.com/golang/protobuf/proto", "golang.org/x/net/context", diff --git a/protoc-gen-grpc-gateway/gengateway/template.go b/protoc-gen-grpc-gateway/gengateway/template.go index c005bafef91..e313a0f667c 100644 --- a/protoc-gen-grpc-gateway/gengateway/template.go +++ b/protoc-gen-grpc-gateway/gengateway/template.go @@ -6,7 +6,7 @@ import ( "strings" "text/template" - "github.com/gengo/grpc-gateway/internal" + "github.com/gengo/grpc-gateway/utilities" "github.com/gengo/grpc-gateway/protoc-gen-grpc-gateway/descriptor" "github.com/golang/glog" ) @@ -49,12 +49,12 @@ func (b binding) QueryParamFilter() queryParamFilter { for _, p := range b.PathParams { seqs = append(seqs, strings.Split(p.FieldPath.String(), ".")) } - return queryParamFilter{internal.NewDoubleArray(seqs)} + return queryParamFilter{utilities.NewDoubleArray(seqs)} } -// queryParamFilter is a wrapper of internal.DoubleArray which provides String() to output DoubleArray.Encoding in a stable and predictable format. +// queryParamFilter is a wrapper of utilities.DoubleArray which provides String() to output DoubleArray.Encoding in a stable and predictable format. type queryParamFilter struct { - *internal.DoubleArray + *utilities.DoubleArray } func (f queryParamFilter) String() string { @@ -63,7 +63,7 @@ func (f queryParamFilter) String() string { encodings[enc] = fmt.Sprintf("%q: %d", str, enc) } e := strings.Join(encodings, ", ") - return fmt.Sprintf("&internal.DoubleArray{Encoding: map[string]int{%s}, Base: %#v, Check: %#v}", e, f.Base, f.Check) + return fmt.Sprintf("&utilities.DoubleArray{Encoding: map[string]int{%s}, Base: %#v, Check: %#v}", e, f.Base, f.Check) } func applyTemplate(p param) (string, error) { @@ -114,7 +114,7 @@ var _ codes.Code var _ io.Reader var _ = runtime.String var _ = json.Marshal -var _ = internal.PascalFromSnake +var _ = utilities.PascalFromSnake `)) handlerTemplate = template.Must(template.New("handler").Parse(` diff --git a/protoc-gen-grpc-gateway/httprule/compile.go b/protoc-gen-grpc-gateway/httprule/compile.go index 8339b896201..90073575181 100644 --- a/protoc-gen-grpc-gateway/httprule/compile.go +++ b/protoc-gen-grpc-gateway/httprule/compile.go @@ -1,7 +1,7 @@ package httprule import ( - "github.com/gengo/grpc-gateway/internal" + "github.com/gengo/grpc-gateway/utilities" ) const ( @@ -22,7 +22,7 @@ type Template struct { Fields []string } -// Compiler compiles internal representation of path templates into marshallable operations. +// Compiler compiles utilities representation of path templates into marshallable operations. // They can be unmarshalled by runtime.NewPattern. type Compiler interface { Compile() Template @@ -30,7 +30,7 @@ type Compiler interface { type op struct { // code is the opcode of the operation - code internal.OpCode + code utilities.OpCode // str is a string operand of the code. // num is ignored if str is not empty. @@ -42,20 +42,20 @@ type op struct { func (w wildcard) compile() []op { return []op{ - {code: internal.OpPush}, + {code: utilities.OpPush}, } } func (w deepWildcard) compile() []op { return []op{ - {code: internal.OpPushM}, + {code: utilities.OpPushM}, } } func (l literal) compile() []op { return []op{ { - code: internal.OpLitPush, + code: utilities.OpLitPush, str: string(l), }, } @@ -67,10 +67,10 @@ func (v variable) compile() []op { ops = append(ops, s.compile()...) } ops = append(ops, op{ - code: internal.OpConcatN, + code: utilities.OpConcatN, num: len(v.segments), }, op{ - code: internal.OpCapture, + code: utilities.OpCapture, str: v.path, }) @@ -100,7 +100,7 @@ func (t template) Compile() Template { } ops = append(ops, consts[op.str]) } - if op.code == internal.OpCapture { + if op.code == utilities.OpCapture { fields = append(fields, op.str) } } diff --git a/protoc-gen-grpc-gateway/httprule/compile_test.go b/protoc-gen-grpc-gateway/httprule/compile_test.go index d4e8b3e7d12..451ae2ad467 100644 --- a/protoc-gen-grpc-gateway/httprule/compile_test.go +++ b/protoc-gen-grpc-gateway/httprule/compile_test.go @@ -4,7 +4,7 @@ import ( "reflect" "testing" - "github.com/gengo/grpc-gateway/internal" + "github.com/gengo/grpc-gateway/utilities" ) const ( @@ -25,19 +25,19 @@ func TestCompile(t *testing.T) { segs: []segment{ wildcard{}, }, - ops: []int{int(internal.OpPush), operandFiller}, + ops: []int{int(utilities.OpPush), operandFiller}, }, { segs: []segment{ deepWildcard{}, }, - ops: []int{int(internal.OpPushM), operandFiller}, + ops: []int{int(utilities.OpPushM), operandFiller}, }, { segs: []segment{ literal("v1"), }, - ops: []int{int(internal.OpLitPush), 0}, + ops: []int{int(utilities.OpLitPush), 0}, pool: []string{"v1"}, }, { @@ -45,7 +45,7 @@ func TestCompile(t *testing.T) { literal("v1"), }, verb: "LOCK", - ops: []int{int(internal.OpLitPush), 0}, + ops: []int{int(utilities.OpLitPush), 0}, pool: []string{"v1"}, }, { @@ -58,9 +58,9 @@ func TestCompile(t *testing.T) { }, }, ops: []int{ - int(internal.OpPush), operandFiller, - int(internal.OpConcatN), 1, - int(internal.OpCapture), 0, + int(utilities.OpPush), operandFiller, + int(utilities.OpConcatN), 1, + int(utilities.OpCapture), 0, }, pool: []string{"name.nested"}, fields: []string{"name.nested"}, @@ -84,15 +84,15 @@ func TestCompile(t *testing.T) { }, }, ops: []int{ - int(internal.OpLitPush), 0, - int(internal.OpLitPush), 1, - int(internal.OpPush), operandFiller, - int(internal.OpLitPush), 2, - int(internal.OpConcatN), 3, - int(internal.OpCapture), 3, - int(internal.OpPushM), operandFiller, - int(internal.OpConcatN), 1, - int(internal.OpCapture), 0, + int(utilities.OpLitPush), 0, + int(utilities.OpLitPush), 1, + int(utilities.OpPush), operandFiller, + int(utilities.OpLitPush), 2, + int(utilities.OpConcatN), 3, + int(utilities.OpCapture), 3, + int(utilities.OpPushM), operandFiller, + int(utilities.OpConcatN), 1, + int(utilities.OpCapture), 0, }, pool: []string{"obj", "a", "b", "name.nested"}, fields: []string{"name.nested", "obj"}, diff --git a/runtime/mux_test.go b/runtime/mux_test.go index 7394bb13a94..d86eba23153 100644 --- a/runtime/mux_test.go +++ b/runtime/mux_test.go @@ -7,7 +7,7 @@ import ( "net/http/httptest" "testing" - "github.com/gengo/grpc-gateway/internal" + "github.com/gengo/grpc-gateway/utilities" "github.com/gengo/grpc-gateway/runtime" ) @@ -37,7 +37,7 @@ func TestMuxServeHTTP(t *testing.T) { patterns: []stubPattern{ { method: "GET", - ops: []int{int(internal.OpLitPush), 0}, + ops: []int{int(utilities.OpLitPush), 0}, pool: []string{"foo"}, }, }, @@ -50,7 +50,7 @@ func TestMuxServeHTTP(t *testing.T) { patterns: []stubPattern{ { method: "GET", - ops: []int{int(internal.OpLitPush), 0}, + ops: []int{int(utilities.OpLitPush), 0}, pool: []string{"foo"}, }, }, @@ -62,12 +62,12 @@ func TestMuxServeHTTP(t *testing.T) { patterns: []stubPattern{ { method: "GET", - ops: []int{int(internal.OpLitPush), 0}, + ops: []int{int(utilities.OpLitPush), 0}, pool: []string{"foo"}, }, { method: "GET", - ops: []int{int(internal.OpPush), 0}, + ops: []int{int(utilities.OpPush), 0}, }, }, reqMethod: "GET", @@ -79,12 +79,12 @@ func TestMuxServeHTTP(t *testing.T) { patterns: []stubPattern{ { method: "GET", - ops: []int{int(internal.OpLitPush), 0}, + ops: []int{int(utilities.OpLitPush), 0}, pool: []string{"foo"}, }, { method: "POST", - ops: []int{int(internal.OpLitPush), 0}, + ops: []int{int(utilities.OpLitPush), 0}, pool: []string{"foo"}, }, }, @@ -97,7 +97,7 @@ func TestMuxServeHTTP(t *testing.T) { patterns: []stubPattern{ { method: "GET", - ops: []int{int(internal.OpLitPush), 0}, + ops: []int{int(utilities.OpLitPush), 0}, pool: []string{"foo"}, }, }, @@ -109,7 +109,7 @@ func TestMuxServeHTTP(t *testing.T) { patterns: []stubPattern{ { method: "GET", - ops: []int{int(internal.OpLitPush), 0}, + ops: []int{int(utilities.OpLitPush), 0}, pool: []string{"foo"}, }, }, @@ -125,12 +125,12 @@ func TestMuxServeHTTP(t *testing.T) { patterns: []stubPattern{ { method: "GET", - ops: []int{int(internal.OpLitPush), 0}, + ops: []int{int(utilities.OpLitPush), 0}, pool: []string{"foo"}, }, { method: "POST", - ops: []int{int(internal.OpLitPush), 0}, + ops: []int{int(utilities.OpLitPush), 0}, pool: []string{"foo"}, }, }, @@ -147,7 +147,7 @@ func TestMuxServeHTTP(t *testing.T) { patterns: []stubPattern{ { method: "GET", - ops: []int{int(internal.OpLitPush), 0}, + ops: []int{int(utilities.OpLitPush), 0}, pool: []string{"foo"}, }, }, diff --git a/runtime/pattern.go b/runtime/pattern.go index 3bb1451707c..694231ff9d7 100644 --- a/runtime/pattern.go +++ b/runtime/pattern.go @@ -5,7 +5,7 @@ import ( "fmt" "strings" - "github.com/gengo/grpc-gateway/internal" + "github.com/gengo/grpc-gateway/utilities" "github.com/golang/glog" ) @@ -17,7 +17,7 @@ var ( ) type op struct { - code internal.OpCode + code utilities.OpCode operand int } @@ -56,19 +56,19 @@ func NewPattern(version int, ops []int, pool []string, verb string) (Pattern, er var stack, maxstack int var vars []string for i := 0; i < l; i += 2 { - op := op{code: internal.OpCode(ops[i]), operand: ops[i+1]} + op := op{code: utilities.OpCode(ops[i]), operand: ops[i+1]} switch op.code { - case internal.OpNop: + case utilities.OpNop: continue - case internal.OpPush, internal.OpPushM: + case utilities.OpPush, utilities.OpPushM: stack++ - case internal.OpLitPush: + case utilities.OpLitPush: if op.operand < 0 || len(pool) <= op.operand { glog.V(2).Infof("negative literal index: %d", op.operand) return Pattern{}, ErrInvalidPattern } stack++ - case internal.OpConcatN: + case utilities.OpConcatN: if op.operand <= 0 { glog.V(2).Infof("negative concat size: %d", op.operand) return Pattern{}, ErrInvalidPattern @@ -79,7 +79,7 @@ func NewPattern(version int, ops []int, pool []string, verb string) (Pattern, er return Pattern{}, ErrInvalidPattern } stack++ - case internal.OpCapture: + case utilities.OpCapture: if op.operand < 0 || len(pool) <= op.operand { glog.V(2).Infof("variable name index out of bound: %d", op.operand) return Pattern{}, ErrInvalidPattern @@ -136,15 +136,15 @@ func (p Pattern) Match(components []string, verb string) (map[string]string, err l := len(components) for _, op := range p.ops { switch op.code { - case internal.OpNop: + case utilities.OpNop: continue - case internal.OpPush, internal.OpLitPush: + case utilities.OpPush, utilities.OpLitPush: if pos >= l { glog.V(1).Infof("insufficient # of segments") return nil, ErrNotMatch } c := components[pos] - if op.code == internal.OpLitPush { + if op.code == utilities.OpLitPush { if lit := p.pool[op.operand]; c != lit { glog.V(1).Infof("literal segment mismatch: got %q; want %q", c, lit) return nil, ErrNotMatch @@ -152,14 +152,14 @@ func (p Pattern) Match(components []string, verb string) (map[string]string, err } stack = append(stack, c) pos++ - case internal.OpPushM: + case utilities.OpPushM: stack = append(stack, strings.Join(components[pos:], "/")) pos = len(components) - case internal.OpConcatN: + case utilities.OpConcatN: n := op.operand l := len(stack) - n stack = append(stack[:l], strings.Join(stack[l:], "/")) - case internal.OpCapture: + case utilities.OpCapture: n := len(stack) - 1 captured[op.operand] = stack[n] stack = stack[:n] @@ -183,19 +183,19 @@ func (p Pattern) String() string { var stack []string for _, op := range p.ops { switch op.code { - case internal.OpNop: + case utilities.OpNop: continue - case internal.OpPush: + case utilities.OpPush: stack = append(stack, "*") - case internal.OpLitPush: + case utilities.OpLitPush: stack = append(stack, p.pool[op.operand]) - case internal.OpPushM: + case utilities.OpPushM: stack = append(stack, "**") - case internal.OpConcatN: + case utilities.OpConcatN: n := op.operand l := len(stack) - n stack = append(stack[:l], strings.Join(stack[l:], "/")) - case internal.OpCapture: + case utilities.OpCapture: n := len(stack) - 1 stack[n] = fmt.Sprintf("{%s=%s}", p.vars[op.operand], stack[n]) } diff --git a/runtime/pattern_test.go b/runtime/pattern_test.go index 878b21c9f29..d81916539a5 100644 --- a/runtime/pattern_test.go +++ b/runtime/pattern_test.go @@ -6,7 +6,7 @@ import ( "strings" "testing" - "github.com/gengo/grpc-gateway/internal" + "github.com/gengo/grpc-gateway/utilities" ) const ( @@ -24,52 +24,52 @@ func TestNewPattern(t *testing.T) { }{ {}, { - ops: []int{int(internal.OpNop), anything}, + ops: []int{int(utilities.OpNop), anything}, stackSizeWant: 0, }, { - ops: []int{int(internal.OpPush), anything}, + ops: []int{int(utilities.OpPush), anything}, stackSizeWant: 1, }, { - ops: []int{int(internal.OpLitPush), 0}, + ops: []int{int(utilities.OpLitPush), 0}, pool: []string{"abc"}, stackSizeWant: 1, }, { - ops: []int{int(internal.OpPushM), anything}, + ops: []int{int(utilities.OpPushM), anything}, stackSizeWant: 1, }, { ops: []int{ - int(internal.OpPush), anything, - int(internal.OpConcatN), 1, + int(utilities.OpPush), anything, + int(utilities.OpConcatN), 1, }, stackSizeWant: 1, }, { ops: []int{ - int(internal.OpPush), anything, - int(internal.OpConcatN), 1, - int(internal.OpCapture), 0, + int(utilities.OpPush), anything, + int(utilities.OpConcatN), 1, + int(utilities.OpCapture), 0, }, pool: []string{"abc"}, stackSizeWant: 1, }, { ops: []int{ - int(internal.OpPush), anything, - int(internal.OpLitPush), 0, - int(internal.OpLitPush), 1, - int(internal.OpPushM), anything, - int(internal.OpConcatN), 2, - int(internal.OpCapture), 2, + int(utilities.OpPush), anything, + int(utilities.OpLitPush), 0, + int(utilities.OpLitPush), 1, + int(utilities.OpPushM), anything, + int(utilities.OpConcatN), 2, + int(utilities.OpCapture), 2, }, pool: []string{"lit1", "lit2", "var1"}, stackSizeWant: 4, }, { - ops: []int{int(internal.OpLitPush), 0}, + ops: []int{int(utilities.OpLitPush), 0}, pool: []string{"abc"}, stackSizeWant: 1, verb: "LOCK", @@ -98,35 +98,35 @@ func TestNewPatternWithWrongOp(t *testing.T) { }, { // op code out of bound - ops: []int{int(internal.OpEnd), 0}, + ops: []int{int(utilities.OpEnd), 0}, }, { // odd number of items - ops: []int{int(internal.OpPush)}, + ops: []int{int(utilities.OpPush)}, }, { // negative index - ops: []int{int(internal.OpLitPush), -1}, + ops: []int{int(utilities.OpLitPush), -1}, pool: []string{"abc"}, }, { // index out of bound - ops: []int{int(internal.OpLitPush), 1}, + ops: []int{int(utilities.OpLitPush), 1}, pool: []string{"abc"}, }, { // negative # of segments - ops: []int{int(internal.OpConcatN), -1}, + ops: []int{int(utilities.OpConcatN), -1}, pool: []string{"abc"}, }, { // negative index - ops: []int{int(internal.OpCapture), -1}, + ops: []int{int(utilities.OpCapture), -1}, pool: []string{"abc"}, }, { // index out of bound - ops: []int{int(internal.OpCapture), 1}, + ops: []int{int(utilities.OpCapture), 1}, pool: []string{"abc"}, }, } { @@ -149,10 +149,10 @@ func TestNewPatternWithStackUnderflow(t *testing.T) { verb string }{ { - ops: []int{int(internal.OpConcatN), 1}, + ops: []int{int(utilities.OpConcatN), 1}, }, { - ops: []int{int(internal.OpCapture), 0}, + ops: []int{int(utilities.OpCapture), 0}, pool: []string{"abc"}, }, } { @@ -182,32 +182,32 @@ func TestMatch(t *testing.T) { notMatch: []string{"example"}, }, { - ops: []int{int(internal.OpNop), anything}, + ops: []int{int(utilities.OpNop), anything}, match: []string{""}, notMatch: []string{"example", "path/to/example"}, }, { - ops: []int{int(internal.OpPush), anything}, + ops: []int{int(utilities.OpPush), anything}, match: []string{"abc", "def"}, notMatch: []string{"", "abc/def"}, }, { - ops: []int{int(internal.OpLitPush), 0}, + ops: []int{int(utilities.OpLitPush), 0}, pool: []string{"v1"}, match: []string{"v1"}, notMatch: []string{"", "v2"}, }, { - ops: []int{int(internal.OpPushM), anything}, + ops: []int{int(utilities.OpPushM), anything}, match: []string{"", "abc", "abc/def", "abc/def/ghi"}, }, { ops: []int{ - int(internal.OpLitPush), 0, - int(internal.OpLitPush), 1, - int(internal.OpPush), anything, - int(internal.OpConcatN), 1, - int(internal.OpCapture), 2, + int(utilities.OpLitPush), 0, + int(utilities.OpLitPush), 1, + int(utilities.OpPush), anything, + int(utilities.OpConcatN), 1, + int(utilities.OpCapture), 2, }, pool: []string{"v1", "bucket", "name"}, match: []string{"v1/bucket/my-bucket", "v1/bucket/our-bucket"}, @@ -221,11 +221,11 @@ func TestMatch(t *testing.T) { }, { ops: []int{ - int(internal.OpLitPush), 0, - int(internal.OpLitPush), 1, - int(internal.OpPushM), anything, - int(internal.OpConcatN), 2, - int(internal.OpCapture), 2, + int(utilities.OpLitPush), 0, + int(utilities.OpLitPush), 1, + int(utilities.OpPushM), anything, + int(utilities.OpConcatN), 2, + int(utilities.OpCapture), 2, }, pool: []string{"v1", "o", "name"}, match: []string{ @@ -245,15 +245,15 @@ func TestMatch(t *testing.T) { }, { ops: []int{ - int(internal.OpLitPush), 0, - int(internal.OpLitPush), 1, - int(internal.OpPush), anything, - int(internal.OpConcatN), 2, - int(internal.OpCapture), 2, - int(internal.OpLitPush), 3, - int(internal.OpPush), anything, - int(internal.OpConcatN), 1, - int(internal.OpCapture), 4, + int(utilities.OpLitPush), 0, + int(utilities.OpLitPush), 1, + int(utilities.OpPush), anything, + int(utilities.OpConcatN), 2, + int(utilities.OpCapture), 2, + int(utilities.OpLitPush), 3, + int(utilities.OpPush), anything, + int(utilities.OpConcatN), 1, + int(utilities.OpCapture), 4, }, pool: []string{"v2", "b", "name", "o", "oname"}, match: []string{ @@ -270,7 +270,7 @@ func TestMatch(t *testing.T) { }, }, { - ops: []int{int(internal.OpLitPush), 0}, + ops: []int{int(utilities.OpLitPush), 0}, pool: []string{"v1"}, verb: "LOCK", match: []string{"v1:LOCK"}, @@ -316,38 +316,38 @@ func TestMatchWithBinding(t *testing.T) { want: make(map[string]string), }, { - ops: []int{int(internal.OpNop), anything}, + ops: []int{int(utilities.OpNop), anything}, want: make(map[string]string), }, { - ops: []int{int(internal.OpPush), anything}, + ops: []int{int(utilities.OpPush), anything}, path: "abc", want: make(map[string]string), }, { - ops: []int{int(internal.OpPush), anything}, + ops: []int{int(utilities.OpPush), anything}, verb: "LOCK", path: "abc:LOCK", want: make(map[string]string), }, { - ops: []int{int(internal.OpLitPush), 0}, + ops: []int{int(utilities.OpLitPush), 0}, pool: []string{"endpoint"}, path: "endpoint", want: make(map[string]string), }, { - ops: []int{int(internal.OpPushM), anything}, + ops: []int{int(utilities.OpPushM), anything}, path: "abc/def/ghi", want: make(map[string]string), }, { ops: []int{ - int(internal.OpLitPush), 0, - int(internal.OpLitPush), 1, - int(internal.OpPush), anything, - int(internal.OpConcatN), 1, - int(internal.OpCapture), 2, + int(utilities.OpLitPush), 0, + int(utilities.OpLitPush), 1, + int(utilities.OpPush), anything, + int(utilities.OpConcatN), 1, + int(utilities.OpCapture), 2, }, pool: []string{"v1", "bucket", "name"}, path: "v1/bucket/my-bucket", @@ -357,11 +357,11 @@ func TestMatchWithBinding(t *testing.T) { }, { ops: []int{ - int(internal.OpLitPush), 0, - int(internal.OpLitPush), 1, - int(internal.OpPush), anything, - int(internal.OpConcatN), 1, - int(internal.OpCapture), 2, + int(utilities.OpLitPush), 0, + int(utilities.OpLitPush), 1, + int(utilities.OpPush), anything, + int(utilities.OpConcatN), 1, + int(utilities.OpCapture), 2, }, pool: []string{"v1", "bucket", "name"}, verb: "LOCK", @@ -372,11 +372,11 @@ func TestMatchWithBinding(t *testing.T) { }, { ops: []int{ - int(internal.OpLitPush), 0, - int(internal.OpLitPush), 1, - int(internal.OpPushM), anything, - int(internal.OpConcatN), 2, - int(internal.OpCapture), 2, + int(utilities.OpLitPush), 0, + int(utilities.OpLitPush), 1, + int(utilities.OpPushM), anything, + int(utilities.OpConcatN), 2, + int(utilities.OpCapture), 2, }, pool: []string{"v1", "o", "name"}, path: "v1/o/my-bucket/dir/dir2/obj", @@ -386,15 +386,15 @@ func TestMatchWithBinding(t *testing.T) { }, { ops: []int{ - int(internal.OpLitPush), 0, - int(internal.OpLitPush), 1, - int(internal.OpPush), anything, - int(internal.OpConcatN), 2, - int(internal.OpCapture), 2, - int(internal.OpLitPush), 3, - int(internal.OpPush), anything, - int(internal.OpConcatN), 1, - int(internal.OpCapture), 4, + int(utilities.OpLitPush), 0, + int(utilities.OpLitPush), 1, + int(utilities.OpPush), anything, + int(utilities.OpConcatN), 2, + int(utilities.OpCapture), 2, + int(utilities.OpLitPush), 3, + int(utilities.OpPush), anything, + int(utilities.OpConcatN), 1, + int(utilities.OpCapture), 4, }, pool: []string{"v2", "b", "name", "o", "oname"}, path: "v2/b/my-bucket/o/obj", @@ -444,49 +444,49 @@ func TestPatternString(t *testing.T) { want: "/", }, { - ops: []int{int(internal.OpNop), anything}, + ops: []int{int(utilities.OpNop), anything}, want: "/", }, { - ops: []int{int(internal.OpPush), anything}, + ops: []int{int(utilities.OpPush), anything}, want: "/*", }, { - ops: []int{int(internal.OpLitPush), 0}, + ops: []int{int(utilities.OpLitPush), 0}, pool: []string{"endpoint"}, want: "/endpoint", }, { - ops: []int{int(internal.OpPushM), anything}, + ops: []int{int(utilities.OpPushM), anything}, want: "/**", }, { ops: []int{ - int(internal.OpPush), anything, - int(internal.OpConcatN), 1, + int(utilities.OpPush), anything, + int(utilities.OpConcatN), 1, }, want: "/*", }, { ops: []int{ - int(internal.OpPush), anything, - int(internal.OpConcatN), 1, - int(internal.OpCapture), 0, + int(utilities.OpPush), anything, + int(utilities.OpConcatN), 1, + int(utilities.OpCapture), 0, }, pool: []string{"name"}, want: "/{name=*}", }, { ops: []int{ - int(internal.OpLitPush), 0, - int(internal.OpLitPush), 1, - int(internal.OpPush), anything, - int(internal.OpConcatN), 2, - int(internal.OpCapture), 2, - int(internal.OpLitPush), 3, - int(internal.OpPushM), anything, - int(internal.OpConcatN), 2, - int(internal.OpCapture), 4, + int(utilities.OpLitPush), 0, + int(utilities.OpLitPush), 1, + int(utilities.OpPush), anything, + int(utilities.OpConcatN), 2, + int(utilities.OpCapture), 2, + int(utilities.OpLitPush), 3, + int(utilities.OpPushM), anything, + int(utilities.OpConcatN), 2, + int(utilities.OpCapture), 4, }, pool: []string{"v1", "buckets", "bucket_name", "objects", "name"}, want: "/v1/{bucket_name=buckets/*}/{name=objects/**}", diff --git a/runtime/query.go b/runtime/query.go index 67448cb7096..82b07886ca3 100644 --- a/runtime/query.go +++ b/runtime/query.go @@ -6,14 +6,14 @@ import ( "reflect" "strings" - "github.com/gengo/grpc-gateway/internal" + "github.com/gengo/grpc-gateway/utilities" "github.com/golang/glog" "github.com/golang/protobuf/proto" ) // PopulateQueryParameters populates "values" into "msg". // A value is ignored if its key starts with one of the elements in "filters". -func PopulateQueryParameters(msg proto.Message, values url.Values, filter *internal.DoubleArray) error { +func PopulateQueryParameters(msg proto.Message, values url.Values, filter *utilities.DoubleArray) error { for key, values := range values { fieldPath := strings.Split(key, ".") if filter.HasCommonPrefix(fieldPath) { @@ -44,7 +44,7 @@ func populateFieldValueFromPath(msg proto.Message, fieldPath []string, values [] if !isLast && m.Kind() != reflect.Struct { return fmt.Errorf("non-aggregate type in the mid of path: %s", strings.Join(fieldPath, ".")) } - f := m.FieldByName(internal.PascalFromSnake(fieldName)) + f := m.FieldByName(utilities.PascalFromSnake(fieldName)) if !f.IsValid() { glog.Warningf("field not found in %T: %s", msg, strings.Join(fieldPath, ".")) return nil diff --git a/runtime/query_test.go b/runtime/query_test.go index 1dc4a990633..4f0aad80b62 100644 --- a/runtime/query_test.go +++ b/runtime/query_test.go @@ -4,7 +4,7 @@ import ( "net/url" "testing" - "github.com/gengo/grpc-gateway/internal" + "github.com/gengo/grpc-gateway/utilities" "github.com/gengo/grpc-gateway/runtime" "github.com/golang/protobuf/proto" ) @@ -12,7 +12,7 @@ import ( func TestPopulateParameters(t *testing.T) { for _, spec := range []struct { values url.Values - filter *internal.DoubleArray + filter *utilities.DoubleArray want proto.Message }{ { @@ -27,7 +27,7 @@ func TestPopulateParameters(t *testing.T) { "string_value": {"str"}, "repeated_value": {"a", "b", "c"}, }, - filter: internal.NewDoubleArray(nil), + filter: utilities.NewDoubleArray(nil), want: &proto3Message{ FloatValue: 1.5, DoubleValue: 2.5, @@ -52,7 +52,7 @@ func TestPopulateParameters(t *testing.T) { "string_value": {"str"}, "repeated_value": {"a", "b", "c"}, }, - filter: internal.NewDoubleArray(nil), + filter: utilities.NewDoubleArray(nil), want: &proto2Message{ FloatValue: proto.Float32(1.5), DoubleValue: proto.Float64(2.5), @@ -73,7 +73,7 @@ func TestPopulateParameters(t *testing.T) { "nested.string_value": {"u"}, "nested_non_null.string_value": {"v"}, }, - filter: internal.NewDoubleArray(nil), + filter: utilities.NewDoubleArray(nil), want: &proto3Message{ Nested: &proto2Message{ Nested: &proto3Message{ @@ -94,7 +94,7 @@ func TestPopulateParameters(t *testing.T) { values: url.Values{ "uint64_value": {"1", "2", "3", "4", "5"}, }, - filter: internal.NewDoubleArray(nil), + filter: utilities.NewDoubleArray(nil), want: &proto3Message{ Uint64Value: 1, }, @@ -116,7 +116,7 @@ func TestPopulateParameters(t *testing.T) { func TestPopulateParametersWithFilters(t *testing.T) { for _, spec := range []struct { values url.Values - filter *internal.DoubleArray + filter *utilities.DoubleArray want proto.Message }{ { @@ -125,7 +125,7 @@ func TestPopulateParametersWithFilters(t *testing.T) { "string_value": {"str"}, "repeated_value": {"a", "b", "c"}, }, - filter: internal.NewDoubleArray([][]string{ + filter: utilities.NewDoubleArray([][]string{ {"bool_value"}, {"repeated_value"}, }), want: &proto3Message{ @@ -139,7 +139,7 @@ func TestPopulateParametersWithFilters(t *testing.T) { "nested.string_value": {"str"}, "string_value": {"str"}, }, - filter: internal.NewDoubleArray([][]string{ + filter: utilities.NewDoubleArray([][]string{ {"nested"}, }), want: &proto3Message{ @@ -153,7 +153,7 @@ func TestPopulateParametersWithFilters(t *testing.T) { "nested.string_value": {"str"}, "string_value": {"str"}, }, - filter: internal.NewDoubleArray([][]string{ + filter: utilities.NewDoubleArray([][]string{ {"nested", "nested"}, }), want: &proto3Message{ @@ -170,7 +170,7 @@ func TestPopulateParametersWithFilters(t *testing.T) { "nested.string_value": {"str"}, "string_value": {"str"}, }, - filter: internal.NewDoubleArray([][]string{ + filter: utilities.NewDoubleArray([][]string{ {"nested", "nested", "string_value"}, }), want: &proto3Message{ diff --git a/third_party/googleapis/google/api/http.pb.go b/third_party/googleapis/google/api/http.pb.go index 27e77746807..17730b915b3 100644 --- a/third_party/googleapis/google/api/http.pb.go +++ b/third_party/googleapis/google/api/http.pb.go @@ -121,6 +121,3 @@ type CustomHttpPattern struct { func (m *CustomHttpPattern) Reset() { *m = CustomHttpPattern{} } func (m *CustomHttpPattern) String() string { return proto.CompactTextString(m) } func (*CustomHttpPattern) ProtoMessage() {} - -func init() { -} diff --git a/utilities/doc.go b/utilities/doc.go new file mode 100644 index 00000000000..cf79a4d5886 --- /dev/null +++ b/utilities/doc.go @@ -0,0 +1,2 @@ +// Package utilities provides members for internal use in grpc-gateway. +package utilities diff --git a/internal/name.go b/utilities/name.go similarity index 94% rename from internal/name.go rename to utilities/name.go index a6d771936c9..e99648c3337 100644 --- a/internal/name.go +++ b/utilities/name.go @@ -1,4 +1,4 @@ -package internal +package utilities import ( "strings" diff --git a/internal/name_test.go b/utilities/name_test.go similarity index 58% rename from internal/name_test.go rename to utilities/name_test.go index 7b1b6b62bbe..a33dde74e8b 100644 --- a/internal/name_test.go +++ b/utilities/name_test.go @@ -1,9 +1,9 @@ -package internal_test +package utilities_test import ( "testing" - "github.com/gengo/grpc-gateway/internal" + "github.com/gengo/grpc-gateway/utilities" ) func TestPascalToSnake(t *testing.T) { @@ -14,9 +14,9 @@ func TestPascalToSnake(t *testing.T) { {input: "prefixed_value", want: "PrefixedValue"}, {input: "foo_id", want: "FooId"}, } { - got := internal.PascalFromSnake(spec.input) + got := utilities.PascalFromSnake(spec.input) if got != spec.want { - t.Errorf("internal.PascalFromSnake(%q) = %q; want %q", spec.input, got, spec.want) + t.Errorf("utilities.PascalFromSnake(%q) = %q; want %q", spec.input, got, spec.want) } } } diff --git a/internal/pattern.go b/utilities/pattern.go similarity index 97% rename from internal/pattern.go rename to utilities/pattern.go index 99680fc3851..28ad9461f86 100644 --- a/internal/pattern.go +++ b/utilities/pattern.go @@ -1,4 +1,4 @@ -package internal +package utilities // An OpCode is a opcode of compiled path patterns. type OpCode int diff --git a/internal/trie.go b/utilities/trie.go similarity index 99% rename from internal/trie.go rename to utilities/trie.go index 03f80d72f8a..c2b7b30dd91 100644 --- a/internal/trie.go +++ b/utilities/trie.go @@ -1,4 +1,4 @@ -package internal +package utilities import ( "sort" diff --git a/internal/trie_test.go b/utilities/trie_test.go similarity index 88% rename from internal/trie_test.go rename to utilities/trie_test.go index 0422b693598..e5d0271dc52 100644 --- a/internal/trie_test.go +++ b/utilities/trie_test.go @@ -1,30 +1,30 @@ -package internal_test +package utilities_test import ( "reflect" "testing" - "github.com/gengo/grpc-gateway/internal" + "github.com/gengo/grpc-gateway/utilities" ) func TestMaxCommonPrefix(t *testing.T) { for _, spec := range []struct { - da internal.DoubleArray + da utilities.DoubleArray tokens []string want bool }{ { - da: internal.DoubleArray{}, + da: utilities.DoubleArray{}, tokens: nil, want: false, }, { - da: internal.DoubleArray{}, + da: utilities.DoubleArray{}, tokens: []string{"foo"}, want: false, }, { - da: internal.DoubleArray{ + da: utilities.DoubleArray{ Encoding: map[string]int{ "foo": 0, }, @@ -35,7 +35,7 @@ func TestMaxCommonPrefix(t *testing.T) { want: false, }, { - da: internal.DoubleArray{ + da: utilities.DoubleArray{ Encoding: map[string]int{ "foo": 0, }, @@ -46,7 +46,7 @@ func TestMaxCommonPrefix(t *testing.T) { want: true, }, { - da: internal.DoubleArray{ + da: utilities.DoubleArray{ Encoding: map[string]int{ "foo": 0, }, @@ -58,7 +58,7 @@ func TestMaxCommonPrefix(t *testing.T) { }, { // foo|bar - da: internal.DoubleArray{ + da: utilities.DoubleArray{ Encoding: map[string]int{ "foo": 0, "bar": 1, @@ -76,7 +76,7 @@ func TestMaxCommonPrefix(t *testing.T) { }, { // foo|bar - da: internal.DoubleArray{ + da: utilities.DoubleArray{ Encoding: map[string]int{ "foo": 0, "bar": 1, @@ -94,7 +94,7 @@ func TestMaxCommonPrefix(t *testing.T) { }, { // foo|bar - da: internal.DoubleArray{ + da: utilities.DoubleArray{ Encoding: map[string]int{ "foo": 0, "bar": 1, @@ -112,7 +112,7 @@ func TestMaxCommonPrefix(t *testing.T) { }, { // foo|bar - da: internal.DoubleArray{ + da: utilities.DoubleArray{ Encoding: map[string]int{ "foo": 0, "bar": 1, @@ -130,7 +130,7 @@ func TestMaxCommonPrefix(t *testing.T) { }, { // foo|foo\.bar|bar - da: internal.DoubleArray{ + da: utilities.DoubleArray{ Encoding: map[string]int{ "foo": 0, "bar": 1, @@ -150,7 +150,7 @@ func TestMaxCommonPrefix(t *testing.T) { }, { // foo|foo\.bar|bar - da: internal.DoubleArray{ + da: utilities.DoubleArray{ Encoding: map[string]int{ "foo": 0, "bar": 1, @@ -170,7 +170,7 @@ func TestMaxCommonPrefix(t *testing.T) { }, { // foo|foo\.bar|bar - da: internal.DoubleArray{ + da: utilities.DoubleArray{ Encoding: map[string]int{ "foo": 0, "bar": 1, @@ -190,7 +190,7 @@ func TestMaxCommonPrefix(t *testing.T) { }, { // foo|foo\.bar|bar - da: internal.DoubleArray{ + da: utilities.DoubleArray{ Encoding: map[string]int{ "foo": 0, "bar": 1, @@ -210,7 +210,7 @@ func TestMaxCommonPrefix(t *testing.T) { }, { // foo|foo\.bar|bar - da: internal.DoubleArray{ + da: utilities.DoubleArray{ Encoding: map[string]int{ "foo": 0, "bar": 1, @@ -239,16 +239,16 @@ func TestMaxCommonPrefix(t *testing.T) { func TestAdd(t *testing.T) { for _, spec := range []struct { tokens [][]string - want internal.DoubleArray + want utilities.DoubleArray }{ { - want: internal.DoubleArray{ + want: utilities.DoubleArray{ Encoding: make(map[string]int), }, }, { tokens: [][]string{{"foo"}}, - want: internal.DoubleArray{ + want: utilities.DoubleArray{ Encoding: map[string]int{"foo": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}, @@ -259,7 +259,7 @@ func TestAdd(t *testing.T) { }, { tokens: [][]string{{"foo"}, {"bar"}}, - want: internal.DoubleArray{ + want: utilities.DoubleArray{ Encoding: map[string]int{ "foo": 0, "bar": 1, @@ -275,7 +275,7 @@ func TestAdd(t *testing.T) { }, { tokens: [][]string{{"foo", "bar"}, {"foo", "baz"}}, - want: internal.DoubleArray{ + want: utilities.DoubleArray{ Encoding: map[string]int{ "foo": 0, "bar": 1, @@ -293,7 +293,7 @@ func TestAdd(t *testing.T) { }, { tokens: [][]string{{"foo", "bar"}, {"foo", "baz"}, {"qux"}}, - want: internal.DoubleArray{ + want: utilities.DoubleArray{ Encoding: map[string]int{ "foo": 0, "bar": 1, @@ -318,7 +318,7 @@ func TestAdd(t *testing.T) { {"foo", "baz", "bar"}, {"qux", "foo"}, }, - want: internal.DoubleArray{ + want: utilities.DoubleArray{ Encoding: map[string]int{ "foo": 0, "bar": 1, @@ -340,7 +340,7 @@ func TestAdd(t *testing.T) { }, }, } { - da := internal.NewDoubleArray(spec.tokens) + da := utilities.NewDoubleArray(spec.tokens) if got, want := da.Encoding, spec.want.Encoding; !reflect.DeepEqual(got, want) { t.Errorf("da.Encoding = %v; want %v; tokens = %#v", got, want, spec.tokens) }