addresscn

package module
v0.0.0-...-22282cd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 28, 2023 License: MIT Imports: 9 Imported by: 0

README

中国地址解析

将中国的地址解析成标准化的行政区划代码或名称。也可以解析省市区等单独元素。

本仓库还处于不可用的状态,主体功能和文档完成后会删除此声明。

Documentation

Overview

addresscn can parse address string to standardize China address. 初始化阶段如果出错 会直接 panic

Index

Constants

This section is empty.

Variables

View Source
var (
	ProviderGithub = "github"
	ProviderCOS    = "cos"
)
View Source
var (
	ErrorNotFound = errors.New("address code not found")
)

Functions

This section is empty.

Types

type Address

type Address struct {
	ProvinceCode string `json:"province_code" gorm:"type:varchar(2)"` // 省 必填
	CityCode     string `json:"city_code" gorm:"type:varchar(4)"`     // 市 必填
	AreaCode     string `json:"area_code" gorm:"type:varchar(6)"`     // 区 必填
	Detail       string `json:"detail" gorm:"type:varchar(255)"`      // 街道一下具体地址 必填
	ZipCode      string `json:"zip_code" gorm:"type:varchar(6)"`      // 邮编 非必填
}

Address 通信地址

type AddressUpdate

type AddressUpdate struct {
	ProvinceCode *string `json:"province_code" gorm:"type:varchar(2)"` // 省 必填
	CityCode     *string `json:"city_code" gorm:"type:varchar(4)"`     // 市 必填
	AreaCode     *string `json:"area_code" gorm:"type:varchar(6)"`     // 区 必填
	Detail       *string `json:"detail" gorm:"type:varchar(255)"`      // 街道一下具体地址 必填
	ZipCode      *string `json:"zip_code" gorm:"type:varchar(6)"`      // 邮编 非必填
}

AddressUpdate 通信地址修改,供 RESTFUL 请求绑定使用

type Area

type Area struct {
	Code         string
	Name         string
	ProvinceCode string
	CityCode     string
}

Area 区/县

type City

type City struct {
	Code         string
	Name         string
	ProvinceCode string
}

City 市

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client 地址解析客户端 请调用方保证初始化完成后再使用 这些数据在初始化阶段完成写入,提供服务后不再写入,所以只有并行读取,是线程安全的。

func NewFromCOS

func NewFromCOS(cos xobj.Client) *Client

NewFromCOS 从腾讯云对象存储获取数据 用了我的其他库 内网速度快

func NewFromGithub

func NewFromGithub() *Client

NewFromGithub 从 modood/Administrative-divisions-of-China 库初始化

func NewFromReader

func NewFromReader(p, c, a io.Reader) *Client

NewFromReader 从 Reader 初始化

func (*Client) AreaName

func (c *Client) AreaName(code string) (string, error)

AreaName 获取县区名称

func (*Client) CityName

func (c *Client) CityName(code string) (string, error)

CityName 获取市名称

func (*Client) GetPCA

func (c *Client) GetPCA() (io.ReadCloser, error)

GetPCA load the province city area stream from cos.

func (*Client) LoadArea

func (c *Client) LoadArea(r io.Reader)

LoadArea load the area data from a io reader.

func (*Client) LoadCity

func (c *Client) LoadCity(r io.Reader)

LoadCity load the city data from a io reader.

func (*Client) LoadProvince

func (c *Client) LoadProvince(r io.Reader)

LoadProvince load the province data from a io reader.

func (*Client) MustParseAddress

func (c *Client) MustParseAddress(src string) (Address, error)

MustParseAddress 解析地址 报告任何错误

func (*Client) ParseAddress

func (c *Client) ParseAddress(src string) (Address, error)

ParseAddress 解析地址 省市解析成功就算成功 忽略区解析失败的错误

func (*Client) ParseCity

func (c *Client) ParseCity(name string) (City, error)

ParseCity 从名字解析市

func (*Client) ParseProvince

func (c *Client) ParseProvince(name string) (string, error)

ParseProvince 从名字解析省份代码

func (*Client) ProvinceName

func (c *Client) ProvinceName(code string) (string, error)

ProvinceName 获取省份名称

type Province

type Province struct {
	Code string
	Name string
}

Province 省/直辖市

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL