Skip to content
Lucas Klassmann edited this page Jun 21, 2018 · 3 revisions

Welcome to the cpfcnpj wiki!

Instalation

Use the go tool for do that:

$ go get github.com/klassmann/cpfcnpj

How to use the library

You need to import the package github.com/klassmann/cpfcnpj like that:

import (
    "github.com/klassmann/cpfcnpj"
)

Basic Example

package main

import (
	"fmt"

	"github.com/klassmann/cpfcnpj"
)

func main() {

	// This will initialize a new CNPJ and clear the string
	cnpj := cpfcnpj.NewCNPJ("70.082.591/0001-79")

	// Verifies if it is a valid document
	if !cnpj.IsValid() {
		panic(fmt.Errorf("it is not a valid document: %v", cnpj))
	}

	// Cleaned output
	fmt.Printf("%v\n", cnpj)
	// Output: 70082591000179

	// Formatted output
	fmt.Println(cnpj.String())
	// Output: 70.082.591/0001-79
}

Tests

There are some tests in the repository, you can use them for understand better the library. You have to clone the repository and after that you will be able run these tests.

$ git clone https://github.com/klassmann/cpfcnpj
$ cd cpfcnpj
$ go test -v
Clone this wiki locally