2020-05-20 08:05:33 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
context "context"
|
|
|
|
)
|
|
|
|
|
|
|
|
// NameCode 省份地区的结构
|
|
|
|
type NameCode struct {
|
|
|
|
Name string
|
|
|
|
Code string
|
|
|
|
Child []*NameCode
|
|
|
|
}
|
|
|
|
|
|
|
|
var province = &KeyList{}
|
|
|
|
|
|
|
|
type provinceserver struct {
|
|
|
|
}
|
|
|
|
|
2020-06-03 03:31:35 +00:00
|
|
|
// Province 省份 与 代码
|
2020-05-20 08:05:33 +00:00
|
|
|
func (ps *provinceserver) Province(ctx context.Context, req *Request) (*NameCodeReply, error) {
|
|
|
|
reply := &NameCodeReply{}
|
|
|
|
|
2020-05-20 08:51:40 +00:00
|
|
|
nc := GetRandomKeyBySlice(province.GetKeys()).(NameCode)
|
2020-05-20 08:05:33 +00:00
|
|
|
reply.Name = nc.Name
|
|
|
|
reply.Code = nc.Code
|
|
|
|
|
|
|
|
return reply, nil
|
|
|
|
}
|
|
|
|
|
2020-06-03 03:31:35 +00:00
|
|
|
// Area 区(市, 悬) 与 代码
|
2020-05-20 08:05:33 +00:00
|
|
|
func (ps *provinceserver) Area(ctx context.Context, req *Request) (*NameCodeReply, error) {
|
|
|
|
reply := &NameCodeReply{}
|
|
|
|
|
2020-05-20 08:51:40 +00:00
|
|
|
nc := GetRandomKeyBySlice(province.GetKeys()).(NameCode)
|
|
|
|
areanc := GetRandomKeyBySlice(nc.Child).(*NameCode)
|
2020-05-20 08:05:33 +00:00
|
|
|
|
|
|
|
reply.Name = areanc.Name
|
|
|
|
reply.Code = areanc.Code
|
|
|
|
|
|
|
|
return reply, nil
|
|
|
|
}
|
|
|
|
|
2020-06-03 03:31:35 +00:00
|
|
|
// City 城市 与 代码
|
2020-05-20 08:05:33 +00:00
|
|
|
func (ps *provinceserver) City(ctx context.Context, req *Request) (*NameCodeReply, error) {
|
|
|
|
reply := &NameCodeReply{}
|
|
|
|
|
2020-05-20 08:51:40 +00:00
|
|
|
nc := GetRandomKeyBySlice(province.GetKeys()).(NameCode)
|
|
|
|
areanc := GetRandomKeyBySlice(nc.Child).(*NameCode)
|
|
|
|
citync := GetRandomKeyBySlice(areanc.Child).(*NameCode)
|
2020-05-20 08:05:33 +00:00
|
|
|
|
|
|
|
reply.Name = citync.Name
|
|
|
|
reply.Code = citync.Code
|
|
|
|
|
|
|
|
return reply, nil
|
|
|
|
}
|
2020-05-20 08:51:40 +00:00
|
|
|
|
2020-06-03 03:31:35 +00:00
|
|
|
// AreaParent 区域 与 代码 与 父类一起 返回
|
2020-05-20 08:51:40 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2020-06-03 03:31:35 +00:00
|
|
|
// CityParent 同上 多级返回
|
2020-05-20 08:51:40 +00:00
|
|
|
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
|
|
|
|
}
|