jpostcode

package module
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2024 License: MIT Imports: 6 Imported by: 0

README

go-jpostcode

Go Reference

  • go-jpostcode is a Go package to find Japanese address data from Japanese postal code.
  • This package requires Go 1.16+.

Usage

// Find an address
address, err := jpostcode.Find("0010928")

// Search addresses (Some addresses have same postal code)
addresses, err := jpostcode.Search("1138654")

// Print address as a JSON
addressJSON, err := address.ToJSON()
if err != nil { // error handling }
fmt.Println(addressJSON)
Example
$ go run github.com/syumai/go-jpostcode/_examples/server@latest
$ curl http://localhost:8090/0010928

Install a CLI tool to get address from postcode

  • A CLI tool is given as jpost.
Installation
go install github.com/syumai/go-jpostcode/cmd/jpost@latest
Usage of jpost
  • To get address, just give postal code as argument.
# Get address from postal code: 0010928.
$ jpost 0010928
{"postcode":"0010928","prefecture":"北海道",...

Update jpostcode-data

$ make update

License

  • MIT

Author

Original data

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound        = fmt.Errorf("postcode is not found")
	ErrInvalidArgument = fmt.Errorf("postcode is invalid")
	ErrInternal        = fmt.Errorf("internal error")
)

Functions

This section is empty.

Types

type Adapter

type Adapter interface {
	SearchAddressesFromPostCode(postCode string) ([]*Address, error)
}

type Address

type Address struct {
	PostCode       string `json:"postCode" mapstructure:"postcode"`
	Prefecture     string `json:"prefecture" mapstructure:"prefecture"`
	PrefectureKana string `json:"prefectureKana" mapstructure:"prefecture_kana"`
	PrefectureCode int    `json:"prefectureCode" mapstructure:"prefecture_code"`
	City           string `json:"city" mapstructure:"city"`
	CityKana       string `json:"cityKana" mapstructure:"city_kana"`
	Town           string `json:"town" mapstructure:"town"`
	TownKana       string `json:"townKana" mapstructure:"town_kana"`
	Street         string `json:"street" mapstructure:"street"`
	OfficeName     string `json:"officeName" mapstructure:"office_name"`
	OfficeNameKana string `json:"officeNameKana" mapstructure:"office_name_kana"`
}

func Find

func Find(postCode string) (*Address, error)
func Search(postCode string) ([]*Address, error)

func (*Address) ToJSON

func (addr *Address) ToJSON() (string, error)

Directories

Path Synopsis
_examples
server command
cmd
jpost command
internal
script
gobdump command

Jump to

Keyboard shortcuts

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