package main import ( context "context" ) // NameCode 省份地区的结构 type NameCode struct { Name string Code string Child []*NameCode } var province = &KeyList{} type provinceserver struct { } func (ps *provinceserver) Province(ctx context.Context, req *Request) (*NameCodeReply, error) { reply := &NameCodeReply{} nc := GetRandomKeyBySlice(province.GetKeys()).(NameCode) reply.Name = nc.Name reply.Code = nc.Code return reply, nil } func (ps *provinceserver) Area(ctx context.Context, req *Request) (*NameCodeReply, error) { reply := &NameCodeReply{} nc := GetRandomKeyBySlice(province.GetKeys()).(NameCode) areanc := GetRandomKeyBySlice(nc.Child).(*NameCode) reply.Name = areanc.Name reply.Code = areanc.Code return reply, nil } func (ps *provinceserver) City(ctx context.Context, req *Request) (*NameCodeReply, error) { reply := &NameCodeReply{} 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 }