Skip to content

Commit

Permalink
Refactor generate cnpj
Browse files Browse the repository at this point in the history
  • Loading branch information
martinusso committed Dec 27, 2019
1 parent 84299b8 commit adb2c8f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,52 @@
[![Coverage Status](https://coveralls.io/repos/github/martinusso/go-docs/badge.svg?branch=master)](https://coveralls.io/github/martinusso/go-docs?branch=master)
[![GoDoc](https://godoc.org/github.com/martinusso/go-docs?status.svg)](https://godoc.org/github.com/martinusso/go-docs)

## Usage

### CPF

`import "github.com/martinusso/go-docs/cpf"`

Valid return a boolean

```
valid := cpf.Valid("08507460003")
```

AssertValid return a boolean and the error if any

```
valid, err := cpf.AssertValid("08507460003")
```

Generate return a random valid CPF

```
doc := cpf.Generate()
```

### CNPJ

`import "github.com/martinusso/go-docs/cnpj"`

Valid return a boolean

```
valid := cnpj.Valid("34700442000162")
```

AssertValid return a boolean and the error if any

```
valid, err := cnpj.AssertValid("34700442000162")
```

Generate return a random valid CNPJ

```
doc := cnpj.Generate()
```

## License

This software is open source, licensed under the The MIT License (MIT). See [LICENSE](https://github.com/martinusso/go-docs/blob/master/LICENSE) for details.
8 changes: 8 additions & 0 deletions cnpj/cnpj.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ func Generate() string {

cnpj := make([]int, 12)
for i := 0; i < 12; i++ {
if i >= 8 && i <= 10 {
cnpj[i] = 0
continue
}
if i == 11 {
cnpj[i] = 1
continue
}
cnpj[i] = rand.Intn(9)
}
checkDigit1 := computeCheckDigit(cnpj)
Expand Down

0 comments on commit adb2c8f

Please sign in to comment.