Documentation
¶
Overview ¶
Package db 提供区域数据文件的相关操作
数据格式:
1:[versions]:{id:name:yearIndex:size{}}
- 1 表示数据格式的版本,采用当前包的 Version 常量;
- versions 表示当前数据文件中的数据支持的年份列表,以逗号分隔;
- id 当前区域的 ID;
- name 当前区域的名称;
- yearIndex 此条数据支持的年份列表,每一个位表示一个年份在 versions 中的索引值;
- size 表示子元素的数量;
Index ¶
- Constants
- Variables
- type DB
- func Load(data []byte, separator string, compress bool, version ...int) (*DB, error)
- func LoadFS(f fs.FS, file, separator string, compress bool, version ...int) (*DB, error)
- func LoadFile(file, separator string, compress bool, version ...int) (*DB, error)
- func New() *DB
- func Unmarshal(data []byte, separator string, version ...int) (*DB, error)deprecated
- func (db *DB) AddItem(regionID, name string, ver int) error
- func (db *DB) AddVersion(ver int) (ok bool)
- func (db *DB) Dump(file string, compress bool) error
- func (db *DB) Find(id ...string) *Region
- func (db *DB) Search(opt *Options) []*Region
- func (db *DB) VersionIndex(ver int) int
- func (db *DB) Versions() []int
- type Options
- type Region
Constants ¶
View Source
const Version = 1
Version 数据文件的版本号
Variables ¶
View Source
var ErrIncompatible = errors.New("数据文件版本不兼容")
ErrIncompatible 数据文件版本不兼容
当数据文件中指定的版本号与当前的 Version 不相等时,返回此错误。
Functions ¶
This section is empty.
Types ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB 区域数据库信息
type Options ¶
type Options struct {
// 表示你需要搜索的地名需要包含的内容
//
// 不能是多个名称的组合,比如"浙江温州",直接写"温州"就可以。
// 也不要提供类似于"居委会"这种无实际意义的地名;
Text string
// 上一级的区域 ID
//
// 为空表示不限制。
Parent string
// 搜索的城市类型
//
// 该值取值于 github.com/issue9/cnregion/id.Level 类型。 多个值可以通过或运算叠加。
// 0 表示所有类型。
Level id.Level
// 最大的搜索数量。0 表示不限制数量。
Max int
// contains filtered or unexported fields
}
Options 搜索选项
Click to show internal directories.
Click to hide internal directories.