jpareacode

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2023 License: MIT Imports: 6 Imported by: 5

README

jpareacode

Go Reference

日本の都道府県名や市区町村名から、都道府県コードや市区町村コードを取得するライブラリ

package main

import (
  jpareacode "github.com/eukarya-inc/jpareacode"
)

func main() {
  jpareacode.PrefectureCodeInt("北海道") // 1
  jpareacode.PrefectureCodeStrings("北海道") // "01"
  jpareacode.PrefectureCodeInts("北海道", "東京都") // [1, 13]
  jpareacode.PrefectureCodeStrings("北海道", "東京都") // ["01", "13"]
  jpareacode.PrefectureName(1) // "北海道"
  jpareacode.PrefectureNames(1, 13) // ["北海道", "東京都"]
  jpareacode.Prefectures // []stirng{"北海道", ...}

  jpareacode.CityByName(13, "千代田区") // &City{PrefCode:13, Name:"千代田区", Code:13101}
  jpareacode.CityByNames("北区") // []City{{PrefCode:1, Name:"北区", Code:1102}, {PrefCode:11, Name:"北区", Code:11102}, ...}
  jpareacode.CityByCode(13101) // &City{PrefCode:13, Name:"千代田区", Code:13101}
  jpareacode.Cities // []City{{PrefCode:13, Name:"千代田区", Code:13101}, ...}
}

データは国土交通省が公開する「都道府県内市区町村一覧取得API」を基にしています。詳しくは以下をご覧ください。

https://www.land.mlit.go.jp/webland/api.html

最終データ更新日:2023/02/20

MIT License

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cities []City
View Source
var FormatPrefectureCode = jpareacodepref.FormatPrefectureCode

FormatPrefectureCode は、intの都道府県コードをstringに変換します。

View Source
var ParsePrefectureCode = jpareacodepref.ParsePrefectureCode

ParsePrefectureCode は、stringの都道府県コードをintに変換します。パースに失敗した場合やコードが無効な場合は0が返されます。

View Source
var PrefectureCodeInt = jpareacodepref.PrefectureCodeInt

PrefectureCodeInt は、都道府県名を基に都道府県コードをintで返します。見つからない場合は0が返されます。

View Source
var PrefectureCodeInts = jpareacodepref.PrefectureCodeInts

PrefectureCodeInts は、複数の都道府県名を基に都道府県コードを[]intで返します。見つからない要素は0になります。

View Source
var PrefectureCodeString = jpareacodepref.PrefectureCodeString

PrefectureCodeString は、都道府県名を基に都道府県コードをstringで返します。見つからない場合は空文字列が返されます。

View Source
var PrefectureCodeStrings = jpareacodepref.PrefectureCodeStrings

PrefectureCodeStrings は、複数の都道府県名を基に都道府県コードを[]stringで返します。見つからない要素は空文字列になります。

View Source
var PrefectureMaxCode = jpareacodepref.PrefectureMaxCode
View Source
var PrefectureMinCode = jpareacodepref.PrefectureMinCode

PrefectureName は、都道府県コードを基に都道府県名をstringで返します。見つからない場合は空文字列が返されます。

PrefectureNames は、複数の都道府県コードを基に都道府県名を[]stringで返します。見つからない要素は空文字列になります。

View Source
var ValidatePrefectureCode = jpareacodepref.ValidatePrefectureCode

ValidatePrefectureCode は、都道府県コードが有効かどうかを返します。

Functions

func FormatCityCode

func FormatCityCode(code int) string

FormatCityCode は、intの市区町村名コードをstringに変換します。無効なコードの場合は空文字列が返されます。

func ParseCityCode

func ParseCityCode(code string) int

ParseCityCode は、stringの市区町村名コードをintに変換します。パースに失敗した場合や無効なコードの場合は0が返されます。

func ValidateCityCode

func ValidateCityCode(code int) bool

ValidateCityCode は、市区町村コードが有効かどうかを返します。

Types

type City

type City struct {
	PrefCode int    `json:"prefCode"`
	Name     string `json:"name"`
	Code     int    `json:"code"`
}

func CitiesByName

func CitiesByName(name string) (res []City)

CitiesByName は、市区町村名に合致する全ての市区町村情報を返します。

func CityByCode

func CityByCode(code int) *City

CityByCode は、市区町村コードを基に市区町村情報を返します。

func CityByName

func CityByName(prefCode int, name string) *City

CityByName は、都道府県コードと市区町村名を基に市区町村情報を返します。

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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