data_workshop/province.go

59 lines
1.2 KiB
Go

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