From 95a9ba87ce04bdbf8db8936f0a87de3c2f6b1d87 Mon Sep 17 00:00:00 2001 From: huangsimin Date: Wed, 20 May 2020 16:51:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E7=9C=81=E5=8C=BA=E7=9A=84?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- base.go | 4 +- proto/province.proto | 20 ++++++ province.go | 52 ++++++++++++-- province.pb.go | 160 +++++++++++++++++++++++++++++++++++++++---- province.pb.gw.go | 156 +++++++++++++++++++++++++++++++++++++++++ province_test.go | 2 +- 6 files changed, 372 insertions(+), 22 deletions(-) diff --git a/base.go b/base.go index c6718af..5b2f3d7 100644 --- a/base.go +++ b/base.go @@ -147,8 +147,8 @@ func GetRandomKey(v IKeyList) interface{} { return v.GetKeys()[rand.Intn(v.GetLength())] } -// GetRandomKeyByList get ikeylist key by random -func GetRandomKeyByList(v interface{}) interface{} { +// GetRandomKeyBySlice get ikeylist key by random +func GetRandomKeyBySlice(v interface{}) interface{} { sli := reflect.ValueOf(v) return sli.Index(rand.Intn(sli.Len())).Interface() } diff --git a/proto/province.proto b/proto/province.proto index 8fbb08e..57f33a5 100644 --- a/proto/province.proto +++ b/proto/province.proto @@ -26,6 +26,13 @@ service ProvinceAreaCity { }; } + rpc AreaParent (Request) returns (NameCodeParentReply){ + option (google.api.http) = { + post: "/v1/area/namecode/parent" + body: "*" + }; + } + rpc City (Request) returns (NameCodeReply){ option (google.api.http) = { post: "/v1/city/namecode" @@ -33,6 +40,13 @@ service ProvinceAreaCity { }; } + rpc CityParent (Request) returns (NameCodeParentReply){ + option (google.api.http) = { + post: "/v1/city/namecode/parent" + body: "*" + }; + } + // rpc CityParent (Request) returns (NameCodeReply){ // option (google.api.http) = { // post: "/v1/city/namecode/parent" @@ -41,6 +55,12 @@ service ProvinceAreaCity { // } } +// The response message containing the greetings +message NameCodeParentReply { + string name = 1; + string code = 2; + NameCodeParentReply parent = 3; +} // The response message containing the greetings message NameCodeReply { diff --git a/province.go b/province.go index 54b2fbe..de3e224 100644 --- a/province.go +++ b/province.go @@ -25,7 +25,7 @@ type provinceserver struct { func (ps *provinceserver) Province(ctx context.Context, req *Request) (*NameCodeReply, error) { reply := &NameCodeReply{} - nc := GetRandomKeyByList(province.GetKeys()).(NameCode) + nc := GetRandomKeyBySlice(province.GetKeys()).(NameCode) reply.Name = nc.Name reply.Code = nc.Code @@ -35,8 +35,8 @@ func (ps *provinceserver) Province(ctx context.Context, req *Request) (*NameCode func (ps *provinceserver) Area(ctx context.Context, req *Request) (*NameCodeReply, error) { reply := &NameCodeReply{} - nc := GetRandomKeyByList(province.GetKeys()).(NameCode) - areanc := GetRandomKeyByList(nc.Child).(*NameCode) + nc := GetRandomKeyBySlice(province.GetKeys()).(NameCode) + areanc := GetRandomKeyBySlice(nc.Child).(*NameCode) reply.Name = areanc.Name reply.Code = areanc.Code @@ -47,12 +47,52 @@ func (ps *provinceserver) Area(ctx context.Context, req *Request) (*NameCodeRepl func (ps *provinceserver) City(ctx context.Context, req *Request) (*NameCodeReply, error) { reply := &NameCodeReply{} - nc := GetRandomKeyByList(province.GetKeys()).(NameCode) - areanc := GetRandomKeyByList(nc.Child).(*NameCode) - citync := GetRandomKeyByList(areanc.Child).(*NameCode) + nc := GetRandomKeyBySlice(province.GetKeys()).(NameCode) + areanc := GetRandomKeyBySlice(nc.Child).(*NameCode) + citync := GetRandomKeyBySlice(areanc.Child).(*NameCode) reply.Name = citync.Name reply.Code = citync.Code return reply, nil } + +func (ps *provinceserver) AreaParent(ctx context.Context, req *Request) (*NameCodeParentReply, error) { + reply := &NameCodeParentReply{} + + nc := GetRandomKeyBySlice(province.GetKeys()).(NameCode) + + parentReply := &NameCodeParentReply{} + parentReply.Name = nc.Name + parentReply.Code = nc.Code + + areanc := GetRandomKeyBySlice(nc.Child).(*NameCode) + reply.Name = areanc.Name + reply.Code = areanc.Code + reply.Parent = parentReply + + return reply, nil +} + +func (ps *provinceserver) CityParent(ctx context.Context, req *Request) (*NameCodeParentReply, error) { + reply := &NameCodeParentReply{} + + nc := GetRandomKeyBySlice(province.GetKeys()).(NameCode) + + parentReply := &NameCodeParentReply{} + parentReply.Name = nc.Name + parentReply.Code = nc.Code + + areanc := GetRandomKeyBySlice(nc.Child).(*NameCode) + areaReply := &NameCodeParentReply{} + areaReply.Name = areanc.Name + areaReply.Code = areanc.Code + areaReply.Parent = parentReply + + citync := GetRandomKeyBySlice(areanc.Child).(*NameCode) + reply.Name = citync.Name + reply.Code = citync.Code + reply.Parent = areaReply + + return reply, nil +} diff --git a/province.pb.go b/province.pb.go index 5bdacef..f9acedb 100644 --- a/province.pb.go +++ b/province.pb.go @@ -25,6 +25,62 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package +// The response message containing the greetings +type NameCodeParentReply struct { + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + Code string `protobuf:"bytes,2,opt,name=code,proto3" json:"code,omitempty"` + Parent *NameCodeParentReply `protobuf:"bytes,3,opt,name=parent,proto3" json:"parent,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *NameCodeParentReply) Reset() { *m = NameCodeParentReply{} } +func (m *NameCodeParentReply) String() string { return proto.CompactTextString(m) } +func (*NameCodeParentReply) ProtoMessage() {} +func (*NameCodeParentReply) Descriptor() ([]byte, []int) { + return fileDescriptor_e183bc545e5b5a19, []int{0} +} + +func (m *NameCodeParentReply) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_NameCodeParentReply.Unmarshal(m, b) +} +func (m *NameCodeParentReply) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_NameCodeParentReply.Marshal(b, m, deterministic) +} +func (m *NameCodeParentReply) XXX_Merge(src proto.Message) { + xxx_messageInfo_NameCodeParentReply.Merge(m, src) +} +func (m *NameCodeParentReply) XXX_Size() int { + return xxx_messageInfo_NameCodeParentReply.Size(m) +} +func (m *NameCodeParentReply) XXX_DiscardUnknown() { + xxx_messageInfo_NameCodeParentReply.DiscardUnknown(m) +} + +var xxx_messageInfo_NameCodeParentReply proto.InternalMessageInfo + +func (m *NameCodeParentReply) GetName() string { + if m != nil { + return m.Name + } + return "" +} + +func (m *NameCodeParentReply) GetCode() string { + if m != nil { + return m.Code + } + return "" +} + +func (m *NameCodeParentReply) GetParent() *NameCodeParentReply { + if m != nil { + return m.Parent + } + return nil +} + // The response message containing the greetings type NameCodeReply struct { Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` @@ -38,7 +94,7 @@ func (m *NameCodeReply) Reset() { *m = NameCodeReply{} } func (m *NameCodeReply) String() string { return proto.CompactTextString(m) } func (*NameCodeReply) ProtoMessage() {} func (*NameCodeReply) Descriptor() ([]byte, []int) { - return fileDescriptor_e183bc545e5b5a19, []int{0} + return fileDescriptor_e183bc545e5b5a19, []int{1} } func (m *NameCodeReply) XXX_Unmarshal(b []byte) error { @@ -74,6 +130,7 @@ func (m *NameCodeReply) GetCode() string { } func init() { + proto.RegisterType((*NameCodeParentReply)(nil), "main.NameCodeParentReply") proto.RegisterType((*NameCodeReply)(nil), "main.NameCodeReply") } @@ -82,22 +139,27 @@ func init() { } var fileDescriptor_e183bc545e5b5a19 = []byte{ - // 238 bytes of a gzipped FileDescriptorProto + // 313 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x2b, 0x28, 0xca, 0x2f, 0xcb, 0xcc, 0x4b, 0x4e, 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0xc9, 0x4d, 0xcc, 0xcc, 0x93, 0xe2, 0x4a, 0x4a, 0x2c, 0x86, 0x8a, 0x48, 0xc9, 0xa4, 0xe7, 0xe7, 0xa7, 0xe7, 0xa4, 0xea, 0x27, 0x16, 0x64, 0xea, 0x27, 0xe6, 0xe5, 0xe5, 0x97, 0x24, 0x96, 0x64, 0xe6, 0xe7, 0x15, 0x43, - 0x64, 0x95, 0xcc, 0xb9, 0x78, 0xfd, 0x12, 0x73, 0x53, 0x9d, 0xf3, 0x53, 0x52, 0x83, 0x52, 0x0b, - 0x72, 0x2a, 0x85, 0x84, 0xb8, 0x58, 0xf2, 0x12, 0x73, 0x53, 0x25, 0x18, 0x15, 0x18, 0x35, 0x38, - 0x83, 0xc0, 0x6c, 0x90, 0x58, 0x72, 0x7e, 0x4a, 0xaa, 0x04, 0x13, 0x44, 0x0c, 0xc4, 0x36, 0xfa, - 0xc1, 0xc8, 0x25, 0x10, 0x00, 0xb5, 0xdb, 0xb1, 0x28, 0x35, 0xd1, 0x39, 0xb3, 0xa4, 0x52, 0x28, - 0x80, 0x8b, 0x03, 0x26, 0x26, 0xc4, 0xab, 0x07, 0x72, 0x8a, 0x5e, 0x50, 0x6a, 0x61, 0x69, 0x6a, - 0x71, 0x89, 0x94, 0x30, 0x84, 0x8b, 0x62, 0x99, 0x92, 0x42, 0xd3, 0xe5, 0x27, 0x93, 0x99, 0xa4, - 0x94, 0x44, 0xf5, 0xcb, 0x0c, 0xf5, 0x61, 0x3e, 0xd1, 0x07, 0xd9, 0x09, 0xb2, 0xc3, 0x8a, 0x51, - 0x4b, 0xc8, 0x83, 0x8b, 0x05, 0x64, 0x3a, 0x51, 0xa6, 0xc9, 0x80, 0x4d, 0x13, 0x53, 0x12, 0x04, - 0x99, 0x96, 0x58, 0x94, 0x9a, 0x88, 0x6e, 0x12, 0xd8, 0x8d, 0x24, 0x9b, 0x94, 0x9c, 0x59, 0x52, - 0x89, 0x6c, 0x92, 0x13, 0x47, 0x14, 0x9b, 0x9e, 0x35, 0x48, 0x57, 0x12, 0x1b, 0x38, 0x10, 0x8d, - 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0xb0, 0xf8, 0xff, 0xa1, 0x86, 0x01, 0x00, 0x00, + 0x64, 0x95, 0x0a, 0xb8, 0x84, 0xfd, 0x12, 0x73, 0x53, 0x9d, 0xf3, 0x53, 0x52, 0x03, 0x12, 0x8b, + 0x52, 0xf3, 0x4a, 0x82, 0x52, 0x0b, 0x72, 0x2a, 0x85, 0x84, 0xb8, 0x58, 0xf2, 0x12, 0x73, 0x53, + 0x25, 0x18, 0x15, 0x18, 0x35, 0x38, 0x83, 0xc0, 0x6c, 0x90, 0x58, 0x72, 0x7e, 0x4a, 0xaa, 0x04, + 0x13, 0x44, 0x0c, 0xc4, 0x16, 0x32, 0xe4, 0x62, 0x2b, 0x00, 0x6b, 0x93, 0x60, 0x56, 0x60, 0xd4, + 0xe0, 0x36, 0x92, 0xd4, 0x03, 0xd9, 0xaf, 0x87, 0xc5, 0xc8, 0x20, 0xa8, 0x42, 0x25, 0x73, 0x2e, + 0x5e, 0x98, 0x34, 0x49, 0x76, 0x19, 0x6d, 0x62, 0xe6, 0x12, 0x08, 0x80, 0xfa, 0xd6, 0xb1, 0x28, + 0x35, 0xd1, 0x39, 0xb3, 0xa4, 0x52, 0x28, 0x80, 0x8b, 0x03, 0x26, 0x26, 0xc4, 0x0b, 0xb1, 0x3c, + 0x28, 0xb5, 0xb0, 0x34, 0xb5, 0xb8, 0x44, 0x4a, 0x18, 0xd5, 0x2d, 0x60, 0xcb, 0x94, 0x14, 0x9a, + 0x2e, 0x3f, 0x99, 0xcc, 0x24, 0xa5, 0x24, 0xaa, 0x5f, 0x66, 0xa8, 0x0f, 0x0b, 0x3b, 0x7d, 0x90, + 0x9d, 0x20, 0x3b, 0xac, 0x18, 0xb5, 0x84, 0x3c, 0xb8, 0x58, 0x40, 0xa6, 0x13, 0x65, 0x9a, 0x0c, + 0xd8, 0x34, 0x31, 0x25, 0x41, 0x90, 0x69, 0x89, 0x45, 0xa9, 0x89, 0x28, 0x26, 0x45, 0x73, 0x71, + 0x81, 0x4c, 0x82, 0x04, 0x02, 0xba, 0x79, 0xb8, 0x43, 0x4a, 0x49, 0x19, 0x6c, 0xaa, 0xac, 0x92, + 0x04, 0x86, 0xa9, 0xfa, 0x90, 0x30, 0x84, 0x3a, 0x13, 0x1c, 0x00, 0x24, 0x3b, 0x33, 0x39, 0xb3, + 0xa4, 0x12, 0xdd, 0x99, 0x20, 0x93, 0x28, 0x73, 0x26, 0x8a, 0xa9, 0x08, 0x67, 0x3a, 0x71, 0x44, + 0xb1, 0xe9, 0x59, 0x83, 0x8c, 0x48, 0x62, 0x03, 0x27, 0x38, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, + 0xff, 0x51, 0x87, 0x58, 0x64, 0xb2, 0x02, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -115,7 +177,9 @@ type ProvinceAreaCityClient interface { // Sends a greeting Province(ctx context.Context, in *Request, opts ...grpc.CallOption) (*NameCodeReply, error) Area(ctx context.Context, in *Request, opts ...grpc.CallOption) (*NameCodeReply, error) + AreaParent(ctx context.Context, in *Request, opts ...grpc.CallOption) (*NameCodeParentReply, error) City(ctx context.Context, in *Request, opts ...grpc.CallOption) (*NameCodeReply, error) + CityParent(ctx context.Context, in *Request, opts ...grpc.CallOption) (*NameCodeParentReply, error) } type provinceAreaCityClient struct { @@ -144,6 +208,15 @@ func (c *provinceAreaCityClient) Area(ctx context.Context, in *Request, opts ... return out, nil } +func (c *provinceAreaCityClient) AreaParent(ctx context.Context, in *Request, opts ...grpc.CallOption) (*NameCodeParentReply, error) { + out := new(NameCodeParentReply) + err := c.cc.Invoke(ctx, "/main.ProvinceAreaCity/AreaParent", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + func (c *provinceAreaCityClient) City(ctx context.Context, in *Request, opts ...grpc.CallOption) (*NameCodeReply, error) { out := new(NameCodeReply) err := c.cc.Invoke(ctx, "/main.ProvinceAreaCity/City", in, out, opts...) @@ -153,12 +226,23 @@ func (c *provinceAreaCityClient) City(ctx context.Context, in *Request, opts ... return out, nil } +func (c *provinceAreaCityClient) CityParent(ctx context.Context, in *Request, opts ...grpc.CallOption) (*NameCodeParentReply, error) { + out := new(NameCodeParentReply) + err := c.cc.Invoke(ctx, "/main.ProvinceAreaCity/CityParent", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // ProvinceAreaCityServer is the server API for ProvinceAreaCity service. type ProvinceAreaCityServer interface { // Sends a greeting Province(context.Context, *Request) (*NameCodeReply, error) Area(context.Context, *Request) (*NameCodeReply, error) + AreaParent(context.Context, *Request) (*NameCodeParentReply, error) City(context.Context, *Request) (*NameCodeReply, error) + CityParent(context.Context, *Request) (*NameCodeParentReply, error) } // UnimplementedProvinceAreaCityServer can be embedded to have forward compatible implementations. @@ -171,9 +255,15 @@ func (*UnimplementedProvinceAreaCityServer) Province(ctx context.Context, req *R func (*UnimplementedProvinceAreaCityServer) Area(ctx context.Context, req *Request) (*NameCodeReply, error) { return nil, status.Errorf(codes.Unimplemented, "method Area not implemented") } +func (*UnimplementedProvinceAreaCityServer) AreaParent(ctx context.Context, req *Request) (*NameCodeParentReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method AreaParent not implemented") +} func (*UnimplementedProvinceAreaCityServer) City(ctx context.Context, req *Request) (*NameCodeReply, error) { return nil, status.Errorf(codes.Unimplemented, "method City not implemented") } +func (*UnimplementedProvinceAreaCityServer) CityParent(ctx context.Context, req *Request) (*NameCodeParentReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method CityParent not implemented") +} func RegisterProvinceAreaCityServer(s *grpc.Server, srv ProvinceAreaCityServer) { s.RegisterService(&_ProvinceAreaCity_serviceDesc, srv) @@ -215,6 +305,24 @@ func _ProvinceAreaCity_Area_Handler(srv interface{}, ctx context.Context, dec fu return interceptor(ctx, in, info, handler) } +func _ProvinceAreaCity_AreaParent_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(Request) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ProvinceAreaCityServer).AreaParent(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/main.ProvinceAreaCity/AreaParent", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ProvinceAreaCityServer).AreaParent(ctx, req.(*Request)) + } + return interceptor(ctx, in, info, handler) +} + func _ProvinceAreaCity_City_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(Request) if err := dec(in); err != nil { @@ -233,6 +341,24 @@ func _ProvinceAreaCity_City_Handler(srv interface{}, ctx context.Context, dec fu return interceptor(ctx, in, info, handler) } +func _ProvinceAreaCity_CityParent_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(Request) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ProvinceAreaCityServer).CityParent(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/main.ProvinceAreaCity/CityParent", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ProvinceAreaCityServer).CityParent(ctx, req.(*Request)) + } + return interceptor(ctx, in, info, handler) +} + var _ProvinceAreaCity_serviceDesc = grpc.ServiceDesc{ ServiceName: "main.ProvinceAreaCity", HandlerType: (*ProvinceAreaCityServer)(nil), @@ -245,10 +371,18 @@ var _ProvinceAreaCity_serviceDesc = grpc.ServiceDesc{ MethodName: "Area", Handler: _ProvinceAreaCity_Area_Handler, }, + { + MethodName: "AreaParent", + Handler: _ProvinceAreaCity_AreaParent_Handler, + }, { MethodName: "City", Handler: _ProvinceAreaCity_City_Handler, }, + { + MethodName: "CityParent", + Handler: _ProvinceAreaCity_CityParent_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "province.proto", diff --git a/province.pb.gw.go b/province.pb.gw.go index f9ce47c..091267b 100644 --- a/province.pb.gw.go +++ b/province.pb.gw.go @@ -99,6 +99,40 @@ func local_request_ProvinceAreaCity_Area_0(ctx context.Context, marshaler runtim } +func request_ProvinceAreaCity_AreaParent_0(ctx context.Context, marshaler runtime.Marshaler, client ProvinceAreaCityClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq Request + var metadata runtime.ServerMetadata + + newReader, berr := utilities.IOReaderFactory(req.Body) + if berr != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) + } + if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.AreaParent(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_ProvinceAreaCity_AreaParent_0(ctx context.Context, marshaler runtime.Marshaler, server ProvinceAreaCityServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq Request + var metadata runtime.ServerMetadata + + newReader, berr := utilities.IOReaderFactory(req.Body) + if berr != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) + } + if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.AreaParent(ctx, &protoReq) + return msg, metadata, err + +} + func request_ProvinceAreaCity_City_0(ctx context.Context, marshaler runtime.Marshaler, client ProvinceAreaCityClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq Request var metadata runtime.ServerMetadata @@ -133,6 +167,40 @@ func local_request_ProvinceAreaCity_City_0(ctx context.Context, marshaler runtim } +func request_ProvinceAreaCity_CityParent_0(ctx context.Context, marshaler runtime.Marshaler, client ProvinceAreaCityClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq Request + var metadata runtime.ServerMetadata + + newReader, berr := utilities.IOReaderFactory(req.Body) + if berr != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) + } + if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.CityParent(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_ProvinceAreaCity_CityParent_0(ctx context.Context, marshaler runtime.Marshaler, server ProvinceAreaCityServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq Request + var metadata runtime.ServerMetadata + + newReader, berr := utilities.IOReaderFactory(req.Body) + if berr != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) + } + if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.CityParent(ctx, &protoReq) + return msg, metadata, err + +} + // RegisterProvinceAreaCityHandlerServer registers the http handlers for service ProvinceAreaCity to "mux". // UnaryRPC :call ProvinceAreaCityServer directly. // StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. @@ -178,6 +246,26 @@ func RegisterProvinceAreaCityHandlerServer(ctx context.Context, mux *runtime.Ser }) + mux.Handle("POST", pattern_ProvinceAreaCity_AreaParent_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_ProvinceAreaCity_AreaParent_0(rctx, inboundMarshaler, server, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_ProvinceAreaCity_AreaParent_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + mux.Handle("POST", pattern_ProvinceAreaCity_City_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() @@ -198,6 +286,26 @@ func RegisterProvinceAreaCityHandlerServer(ctx context.Context, mux *runtime.Ser }) + mux.Handle("POST", pattern_ProvinceAreaCity_CityParent_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_ProvinceAreaCity_CityParent_0(rctx, inboundMarshaler, server, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_ProvinceAreaCity_CityParent_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } @@ -279,6 +387,26 @@ func RegisterProvinceAreaCityHandlerClient(ctx context.Context, mux *runtime.Ser }) + mux.Handle("POST", pattern_ProvinceAreaCity_AreaParent_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_ProvinceAreaCity_AreaParent_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_ProvinceAreaCity_AreaParent_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + mux.Handle("POST", pattern_ProvinceAreaCity_City_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() @@ -299,6 +427,26 @@ func RegisterProvinceAreaCityHandlerClient(ctx context.Context, mux *runtime.Ser }) + mux.Handle("POST", pattern_ProvinceAreaCity_CityParent_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_ProvinceAreaCity_CityParent_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_ProvinceAreaCity_CityParent_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } @@ -307,7 +455,11 @@ var ( pattern_ProvinceAreaCity_Area_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "area", "namecode"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_ProvinceAreaCity_AreaParent_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v1", "area", "namecode", "parent"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_ProvinceAreaCity_City_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "city", "namecode"}, "", runtime.AssumeColonVerbOpt(true))) + + pattern_ProvinceAreaCity_CityParent_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v1", "city", "namecode", "parent"}, "", runtime.AssumeColonVerbOpt(true))) ) var ( @@ -315,5 +467,9 @@ var ( forward_ProvinceAreaCity_Area_0 = runtime.ForwardResponseMessage + forward_ProvinceAreaCity_AreaParent_0 = runtime.ForwardResponseMessage + forward_ProvinceAreaCity_City_0 = runtime.ForwardResponseMessage + + forward_ProvinceAreaCity_CityParent_0 = runtime.ForwardResponseMessage ) diff --git a/province_test.go b/province_test.go index 562bf6f..7180dfa 100644 --- a/province_test.go +++ b/province_test.go @@ -136,5 +136,5 @@ func estHunterCountry(t *testing.T) { func estLoadProvince(t *testing.T) { kl := &KeyList{} LoadGob("./data/province.gob", kl) - t.Error(GetRandomKeyByList(kl.GetKeys()).(NameCode)) + t.Error(GetRandomKeyBySlice(kl.GetKeys()).(NameCode)) }