Skip to content

IgorHalfeld/lagoinha

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

75 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lagoinha

Library to get full address of a Brazilian zip code.
Works with VipCep, Correios, and many more.


gopherbadger-tag-do-not-edit

Lagoinha is a package that uses APIs to find complete addresses by a provided zip code. The lib dispatches several requests at the same time and returns with the one that finished first.

Por que esse nome

It's a Brazilian meme vídeo! (onde é que eu tô, lagoinha, CEP, endereço...)

Install

go get -u https://github.com/IgorHalfeld/lagoinha.git

How to use

package main

import (
	"fmt"

	"github.com/igorhalfeld/lagoinha"
)

func main() {
	// get amount of cep providers enabled
	fmt.Println("Total amount of cep providers:", lagoinha.GetTotalAmountOfCepProviders())

	/*
	// if you want to use without handling channels
	addr, err := lagoinha.GetAddressSync("15809240", &lagoinha.GetAddressOptions{
		PreferenceForAPI: "Apicep",
	})
	*/

	chResp, chErr := lagoinha.GetAddress("04568000")

	select {
	case address := <-chResp:
		fmt.Printf("Response: %+v\n", address)
	case err := <-chErr:
		fmt.Printf("Error: %+v\n", err)
	}
}

and you can also set a preference api

chResp, chErr := lagoinha.GetAddress("04568000", &lagoinha.GetAddressOptions{
	PreferenceForAPI: "ViaCEP",
})

logo by @nelsonsecco