br

package module
v0.0.0-...-5cb34da Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2025 License: MIT Imports: 5 Imported by: 0

README

br

Note: This project is currently in its early stages and is a work in progress (WIP). Please refrain from using it in a production environment. The API is subject to change without prior notice until the release of v1.0.0.

Goal

The aim of this project is to develop a high-performance Go library tailored for handling Brazilian documents.

Documentation

Overview

Package br provides utility functions and methods for dealing with Brazilian documents.

This package includes validators, generators 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

View Source
var ErrInvalidCNH = errors.New("br: invalid cnh")

ErrInvalidCNH is an error returned when an invalid CNH is encountered.

View Source
var ErrInvalidCNPJ = errors.New("br: invalid cnpj")

ErrInvalidCNPJ is an error returned when an invalid CNPJ is encountered.

View Source
var ErrInvalidCNS = errors.New("br: invalid cns")

ErrInvalidCNS is an error returned when an invalid CNS is encountered.

View Source
var ErrInvalidCPF = errors.New("br: invalid cpf")

ErrInvalidCPF is an error returned when an invalid CPF is encountered.

View Source
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 CNH

type CNH string

CNH represents a Brazilian driver's license number.

func GenerateCNH

func GenerateCNH() CNH

GenerateCNH generates a pseudo-random valid CNH.

func NewCNH

func NewCNH(s string) (CNH, error)

NewCNH creates a new CNH instance from a string representation.

It verifies the CNH's validity using checksum digits.

func (CNH) IsValid

func (cnh CNH) IsValid() bool

IsValid checks whether the provided CNH is valid based on its checksum digits.

func (CNH) String

func (cnh CNH) String() string

String returns the string representation of CNH.

type CNPJ

type CNPJ string

CNPJ represents a Brazilian CNPJ.

func GenerateCNPJ

func GenerateCNPJ() CNPJ

GenerateCNPJ generates a pseudo-random valid CNPJ.

func NewCNPJ

func NewCNPJ(s string) (CNPJ, error)

NewCNPJ creates a new CNPJ instance from a string representation.

It verifies the CNPJ's validity using checksum digits.

func (CNPJ) AlphaNumerical

func (cnpj CNPJ) AlphaNumerical() string

func (CNPJ) IsValid

func (cnpj CNPJ) IsValid() bool

IsValid checks whether the provided CNPJ is valid based on its checksum digits.

func (CNPJ) String

func (cnpj CNPJ) String() string

String returns the formatted CNPJ string with punctuation as XX.XXX.XXX/XXXX-XX.

func (CNPJ) Value

func (cnpj CNPJ) Value() (driver.Value, error)

Value implements the driver.Valuer interface for CNPJ.

type CNS

type CNS string

CNS represents a Brazilian CNS.

func GenerateCNS

func GenerateCNS() CNS

GenerateCNS generates a pseudo-random valid CNS.

func NewCNS

func NewCNS(s string) (CNS, error)

NewCNS creates a new CNS instance from a string representation.

It verifies the CNS's validity using checksum digits.

func (CNS) IsValid

func (cns CNS) IsValid() bool

IsValid checks whether the provided CNS is valid based on its checksum digits.

func (CNS) String

func (cns CNS) String() string

String returns the CNS formatted as XXX XXXX XXXX XXXX.

func (CNS) Value

func (cns CNS) Value() (driver.Value, error)

Value implements the driver.Valuer interface for CNS.

type CPF

type CPF string

CPF represents a Brazilian CPF.

func GenerateCPF

func GenerateCPF() CPF

GenerateCPF generates a pseudo-random valid CPF.

func NewCPF

func NewCPF(s string) (CPF, error)

NewCPF creates a new CPF instance from a string representation.

It verifies the CPF's validity using checksum digits.

func (CPF) IsValid

func (cpf CPF) IsValid() bool

IsValid checks whether the provided CPF is valid based on its checksum digits.

func (CPF) String

func (cpf CPF) String() string

String returns the formatted CPF string with punctuation as XXX.XXX.XXX-XX.

func (CPF) Value

func (c CPF) Value() (driver.Value, error)

Value implements the driver.Valuer interface for CPF.

type Plate

type Plate string

Plate represents a Brazilian vehicle license plate.

func GeneratePlate

func GeneratePlate() Plate

GeneratePlate generates a pseudo-random valid Plate.

func NewPlate

func NewPlate(s string) (Plate, error)

NewPlate creates a new Plate instance from a string representation.

func (Plate) IsValid

func (p Plate) IsValid() bool

IsValid checks whether the provided license plate is valid based on specific formatting rules.

IsValid will return true if the plate if either a MercoSul or a Brazilian type plate.

The formats accepted are: XXXXXXX, XXX-XXXX, XXX.XXXX

func (Plate) String

func (p Plate) String() string

String returns the license plate as an uppercase formatted string.

String always returns the plate in the XXX-XXXX format and in uppercase.

func (Plate) Value

func (p Plate) Value() (driver.Value, error)

Value implements the driver.Valuer interface for Plate.

Directories

Path Synopsis
x

Jump to

Keyboard shortcuts

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