vnprovince

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2023 License: MIT Imports: 5 Imported by: 0

README

vnprovince

vnprovince is a Golang library that provides a list of Vietnam administrative divisions, including tỉnh thành (provinces), quận huyện (districts), and phường xã (communes/wards). The library includes both the name and code for each administrative division, as defined by the General Statistics Office of Vietnam (Tổng cục Thống kê).

Installation

You can install the library using go get:

go get github.com/TcMits/vnprovince

Usage

To use the vnprovince library in your Golang project, simply import it and use the provided functions to access the administrative divisions. Here's a simple example:

go

package main

import (
  "fmt"
  "github.com/TcMits/vnprovince"
)

func main() {
  provinces, err := vnprovince.GetProvinces()
  if err != nil {
    fmt.Println(err)
  }

  for _, province := range provinces {
    fmt.Println(province.Name)
  }
}

Contributing

Contributions to the vnprovince library are welcome! If you find a bug or have an idea for a new feature, please open an issue or submit a pull request.

Data

Documentation

Index

Constants

View Source
const (
	// districtsCapacity is the number of districts.
	DistrictsLength = 705
)
View Source
const DivisionPath = "data/divisions.csv"

DivisionPath is the path to the divisions.csv file.

View Source
const DivisionsLength = 10604

DivisionsLength the number of divisions in the data directory.

View Source
const ProvincesLength = 63

ProvincesLength is the number of provinces.

View Source
const (
	// WardsLength is the number of wards.
	WardsLength = 10599
)

Variables

View Source
var DataDirFS embed.FS

DataDirFS is the filesystem containing the data directory.

Functions

func EachDistrict

func EachDistrict(fn func(d District) error) error

EachDistrict iterates over all districts and wards.

func EachDivision

func EachDivision(fn func(d Division) error) error

EachDivision calls fn for each division in the data directory.

func EachProvince

func EachProvince(fn func(p Province) error) error

EachProvince iterates over all provinces and districts.

func EachWard

func EachWard(fn func(w Ward) error) error

EachWard iterates over all wards.

Types

type District

type District struct {
	Code  int64  `json:"code"`
	Name  string `json:"name"`
	Wards []Ward `json:"wards"`
}

District is a district in Vietnam.

func GetDistricts

func GetDistricts() ([]*District, error)

GetDistricts returns all districts and wards.

type Division

type Division struct {
	ProvinceCode int64  `json:"provinceCode"`
	DistrictCode int64  `json:"districtCode"`
	WardCode     int64  `json:"wardCode"`
	ProvinceName string `json:"provinceName"`
	DistrictName string `json:"districtName"`
	WardName     string `json:"wardName"`
}

Division is a division of Vietnam.

func GetDivisions

func GetDivisions() ([]*Division, error)

GetDivisions returns all divisions in the data directory.

type Province

type Province struct {
	Code      int64      `json:"code"`
	Name      string     `json:"name"`
	Districts []District `json:"districts"`
}

Province represents a province.

func GetProvinces

func GetProvinces() ([]*Province, error)

GetProvinces returns all provinces and districts.

type Ward

type Ward struct {
	Code int64  `json:"code"`
	Name string `json:"name"`
}

Ward is a ward in Vietnam.

func GetWards

func GetWards() ([]*Ward, error)

GetWards returns all wards.

Jump to

Keyboard shortcuts

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