Documentation ¶
Overview ¶
Package br provides utility functions and methods for dealing with Brazilian documents.
This package includes validators and formatters for various Brazilian documents, such as CPF and CNPJ, as well as functions for handling Brazilian postal codes (CEP).
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidUF is returned when an invalid state (UF) code is passed. ErrInvalidUF = errors.New("br: invalid uf passed") // ErrInvalidCEP is returned when an invalid CEP code is passed. ErrInvalidCEP = errors.New("br: invalid cep passed") // ErrInvalidSerializedAddress is returned when trying to deserialize an // invalid string into an Address. ErrInvalidSerializedAddress = errors.New( "br: invalid serialized address", ) )
var ( // ErrInvalidCNH is an error returned when an invalid CNH is encountered. ErrInvalidCNH = errors.New("br: invalid cnh passed") )
var ( // ErrInvalidCNPJ is an error returned when an invalid CNPJ is encountered. ErrInvalidCNPJ = errors.New("br: invalid cnpj passed") )
var ( // ErrInvalidCNS is an error returned when an invalid CNS is encountered. ErrInvalidCNS = errors.New("br: invalid cns passed") )
var ( // ErrInvalidCPF is an error returned when an invalid CPF is encountered. ErrInvalidCPF = errors.New("br: invalid cpf passed") )
var ErrInvalidPlate = errors.New("br: invalid license plate")
ErrInvalidPlate is an error returned when an invalid license plate is encountered.
Functions ¶
This section is empty.
Types ¶
type Address ¶
type Address struct { UF UF `json:"uf"` CEP CEP `json:"cep"` Localidade string `json:"localidade"` Logradouro string `json:"logradouroDNEC"` Complemento string `json:"complemento"` Bairro string `json:"bairro"` NomeUnidade string `json:"nomeUnidade"` }
Address represents an address associated with a Brazilian CEP.
func (*Address) Deserialize ¶
Deserialize parses a serialized string and populates the Address fields.
func (Address) Serialize ¶
Serialize converts the Address instance into a serialized string representation.
This can be used to store the address as a string on a database, for example.
type CEP ¶
type CEP string
CEP represents a Brazilian postal code (Código de Endereçamento Postal).
func NewCEP ¶
NewCEP creates a CEP instance from a string representation.
It verifies the length of the CEP, the digits, and checks the cache for known invalid CEPs. It does not make requests to APIs to validate the corresponding address if the CEP is not in cache.
To check if this CEP actually represents an Address, call the CEP.ToAddress method.
func (CEP) IsValid ¶
IsValid checks whether the provided CEP is valid based on its length, digits and check the caches for known invalid CEPs.
It does not make requests to APIs to validate the corresponding address.
To check if this CEP actually represents an Address, call the CEP.ToAddress method.
type CNH ¶
type CNH string
CNH represents a Brazilian driver's license number.
func NewCNH ¶
NewCNH creates a new CNH instance from a string representation.
It verifies the CNH's validity using checksum digits.
type CNPJ ¶
type CNPJ string
CNPJ represents a Brazilian CNPJ.
func NewCNPJ ¶
NewCNPJ creates a new CNPJ instance from a string representation.
It verifies the CNPJ's validity using checksum digits.
type CNS ¶
type CNS string
CNS represents a Brazilian CNS.
func NewCNS ¶
NewCNS creates a new CNS instance from a string representation.
It verifies the CNS's validity using checksum digits.
type CPF ¶
type CPF string
CPF represents a Brazilian CPF.
func NewCPF ¶
NewCPF creates a new CPF instance from a string representation.
It verifies the CPF's validity using checksum digits.
type Plate ¶
type Plate string
Plate represents a Brazilian vehicle license plate.
type UF ¶
type UF uint8
UF stands for Unidade Federativa and represents a Brazilian state.
func NewUFFromStr ¶
NewUFFromStr creates a UF instance from a string representation of the state's name or abbreviation.
func (UF) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface for UF.
func (UF) UnidadeFederativa ¶
UnidadeFederativa returns the full name of the UF, such as Rio de Janeiro.
func (*UF) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface for UF.