Giter Site home page Giter Site logo

boostport / address Goto Github PK

View Code? Open in Web Editor NEW
88.0 88.0 16.0 891 KB

Address is a Go library that validates and formats addresses using data generated from Google's Address Data Service

License: Apache License 2.0

Go 100.00%
address formatting go validation

address's People

Contributors

boostport-bot avatar dependabot[bot] avatar eugenio-bolt avatar f21 avatar github-actions[bot] avatar natebrennand avatar ping-localhost avatar sethengland avatar web-flow avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

address's Issues

DB generation

For example you create a User in the DB and then want to record their address, but use a lookup table for Country, City.

Everyone uses different DB and DAL, so maybe we can generate a DB CSV as part of the gen process.

I use Ent, because I am lazy :) But it does work well with atlas. So from a CSV I can write a bit of code to manage that.

Does not validate addresses ?

change "AU" to "AUfoo", and it still passes...

// NewValid creates a new Address. If the address is invalid, an error is returned.

package main

import (
	"log"

	"github.com/Boostport/address"
	"github.com/hashicorp/go-multierror"
)

func main() {
	addr, err := address.NewValid(
		address.WithCountry("AUfoo"), // Must be an ISO 3166-1 country code
		address.WithName("John Citizen"),
		address.WithOrganization("Some Company Pty Ltd"),
		address.WithStreetAddress([]string{
			"525 Collins Street",
		}),
		address.WithLocality("Melbourne"),
		address.WithAdministrativeArea("VIC"), // If the country has a pre-defined list of admin areas (like here), you must use the key and not the name
		address.WithPostCode("3000"),
	)

	if err != nil {
		// If there was an error and you want to find out which validations failed,
		// type switch it as a *multierror.Error to access the list of errors
		if merr, ok := err.(*multierror.Error); ok {
			for _, subErr := range merr.Errors {
				if subErr == address.ErrInvalidCountryCode {
					log.Fatalf(subErr.Error())
				}
			}
		}
	}

	// Use addr here
	log.Print("log")
	log.Print("Country:            " + addr.Country)
	log.Print("Name:               " + addr.Name)
	log.Print("Organization:       " + addr.Organization)
	log.Print("Locality:           " + addr.Locality)
	log.Print("DependentLocality:  " + addr.DependentLocality)
	log.Print("AdministrativeArea: " + addr.AdministrativeArea)
}

PostCodeRegex Doesn't Require Exact Match to Pass Validation.

regexp.MatchString used in checkPostCode returns true as long as the test address contains a match, but doesn't enforce an exact match.

This is causing issues for us where users are entering in extra information into the address form. E.G. NSW 3500 is accepted as a valid post code for Australia NSW, whereas the correct post code is 3500.

A simple fix for this might be to wrap the top-level regex with ^()$. E.g. \d{4} would become ^(\d{4})$.

Go generate - stringer.exe not found

Had an issue with running go generate.
Output:

Generating code...
Formatting generated code...
Total time taken: 1m31.7646708s
constants.go:1: running "stringer": exec: "stringer": executable file not found in %PATH%

Fixed it with:

go get golang.org/x/tools/cmd/stringer

Maybe add as dependency somewhere or in readme

Administrative area keys for China

Hi,

I wanted to inquire about some observations I've made in generated data:

  • Administrative Area Keys: The keys used to identify administrative areas in China appear to be numeric within the data. However, the ISO 3166-2 codes is not numeric. Please refer to https://en.wikipedia.org/wiki/ISO_3166-2:CN.

  • Locality IDs and Language: The locality IDs for China's administrative areas seem to be presented in Han characters for the "en" (English) language. Shouldn't these IDs be in English language?

The current format causes inconsistencies while attempting to interact with the library for Chinese addresses. Also, using Han characters for locality IDs in the "en" language could lead to confusion for users expecting English.

Is it possible to adopt ISO 3166-2 standard for administrative area keys in China and displaying locality IDs in English for the "en" language?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.