id

package
v2.0.0-...-49787b7 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package id 针对 ID 的一些操作函数

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fill

func Fill(id string, level Level) string

Fill 为 id 填充后缀的 0

id 为原始值; level 为需要达到的行政级别,最终的长度为 Length(level)。

func Length

func Length(level Level) int

Length 获取各个类型 ID 的有效果长度

func Parent

func Parent(id string) string

Parent 获取 id 的上一级行政区域的 ID

330312123456 => 330312123

func Prefix

func Prefix(id string) string

Prefix 获取 ID 的非零前缀

330312123456 => 330312123456
330312123000 => 330312123

func Split

func Split(id string) (province, city, county, town, village string)

Split 将一个区域 ID 按区域进行划分

func SplitFilter

func SplitFilter(id string) []string

SplitFilter 将 id 按区域进行划分且过滤掉零值的区域

330312123000 => 33 03 12 123

如果传递的是零值,则返回空数组。

Types

type Level

type Level uint8

Level 表示区域的级别

const (
	Village Level = 1 << iota
	Town
	County
	City
	Province

	AllLevel = Village + Town + County + City + Province
)

对区域级别的定义

Jump to

Keyboard shortcuts

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