i18naddress

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2023 License: MIT Imports: 14 Imported by: 0

README

i18naddress can tell you all the names of cities, states, provinces of all nations around the world.

Developed and tested with Go >= 1.18.

Installation

$ go get github.com/site-name/i18naddress

Usage

package main

import (
  "github.com/site-name/i18naddress"
  "log"
)

func main() {
  
  params := &i18naddress.Params{
    CountryCode: "vn",
  }

  rules, err := i18naddress.GetValidationRules(params)
  if err != nil {
    log.Fatalln(err)
  }

  fmt.Println(rules)
}

All ideas are borrowed from https://github.com/mirumee/google-i18n-address

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	VALID_COUNTRY_CODE   *regexp.Regexp    // regexp for checking country code
	FORMAT_REGEX         *regexp.Regexp    //
	VALIDATION_DATA_PATH string            // path to .json files
	FIELD_MAPPING        map[string]string // short name representations
	KNOWN_FIELDS         []string          //
)

Functions

func FormatAddress

func FormatAddress(address *Params, latin bool) (string, error)

func GetFieldOrder

func GetFieldOrder(address *Params, latin bool) ([][]string, error)

func LoadValidationData

func LoadValidationData(countryCode string) (io.Reader, error)

LoadValidationData

func RegexesToStrings

func RegexesToStrings(in []*regexp.Regexp) []string

Types

type ErrorMap

type ErrorMap map[string]string

ErrorMap is map

func (ErrorMap) Error

func (e ErrorMap) Error() string

type InvalidCodeErr

type InvalidCodeErr struct {
	// contains filtered or unexported fields
}

InvalidCodeErr indicate given country code is invalid

func (*InvalidCodeErr) Error

func (i *InvalidCodeErr) Error() string

type Params

type Params struct {
	CountryArea   string
	CountryCode   string
	City          string
	CityArea      string
	PostalCode    string
	StreetAddress string
	SortingCode   string
}

func NormalizeAddress

func NormalizeAddress(address *Params) (p *Params, errorMap map[string]string)

func (*Params) Copy

func (p *Params) Copy() *Params

func (*Params) GetProperty

func (p *Params) GetProperty(name string) string

func (*Params) Patch

func (p *Params) Patch(name string, value string)

type ValidationRules

type ValidationRules struct {
	CountryCode        string
	CountryName        string
	AddressFormat      string
	AddressLatinFormat string
	AllowedFields      []string
	RequiredFields     []string
	UpperFields        []string
	CountryAreaType    string
	CountryAreaChoices [][2]string
	CityType           string
	CityChoices        [][2]string
	CityAreaType       string
	CityAreaChoices    [][2]string
	PostalCodeType     string
	PostalCodeMatchers []*regexp.Regexp
	PostalCodeExamples []string
	PostalCodePrefix   string
}

func GetValidationRules

func GetValidationRules(address *Params) (*ValidationRules, error)

GetValidationRules get validation rules for given params.

there are 3 error types might be returned:

nil, *InvalidCodeErr, json (encoding/decoding) error

func (*ValidationRules) String

func (v *ValidationRules) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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