···99 runs-on: ubuntu-latest
1010 steps:
11111212- - name: Set up Go 1.13
1212+ - name: Set up Go 1.14
1313 uses: actions/setup-go@v1
1414 with:
1515- go-version: 1.13
1515+ go-version: 1.14
1616 id: go
17171818 - name: Check out code into the Go module directory
+28-5
README.md
···11-# Go CPF 
11+# Go CPF []()[](https://godoc.org/github.com/cuducos/go-cpf)
22+33+A Go module to validate CPF numbers (Brazilian unique identifier for the Federal Revenue).
44+55+```go
66+package main
77+88+import "github.com/cuducos/go-cpf"
99+1010+1111+func main() {
1212+ // these return true
1313+ cpf.IsValid("23858488135")
1414+ cpf.IsValid("238.584.881-35")
1515+1616+ // these return false
1717+ cpf.IsValid("111.111.111-11")
1818+ cpf.IsValid("123.456.769/01")
1919+ cpf.IsValid("ABC.DEF.GHI-JK")
2020+ cpf.IsValid("123")
22133-Three things about this repo:
2222+ // this returns 11111111111
2323+ cpf.Unmask("111.111.111-11")
42455-1. I just started to learn [Go](https://golang.org/) with [_Learn Go With Tests_](https://quii.gitbook.io/learn-go-with-tests/) and this CPF (Brazilian unique identifier for the Federal Revenue) validation script is actually **my very first lines in Go** (except the ones from the book)
66-2. I'm sharing it here to get **feedback** ❤️
77-3. It's not a proper or usable package yet, I just expect **`go test`** to pass : )
2525+ // this returns 111.111.111-11
2626+ cpf.Mask("11111111111")
2727+}
2828+```
2929+3030+I started to learn [Go](https://golang.org/) with [_Learn Go With Tests_](https://quii.gitbook.io/learn-go-with-tests/) and this CPF (Brazilian unique identifier for the Federal Revenue) validation script is actually **my very first lines in Go** (except the ones from the book). I'm sharing it here to get **feedback** ❤️
+12-18
cpf.go
···77 "strings"
88)
991010-//auxiliar type and variable to build a set
1010+//These are auxiliar type and variable to build a set
1111type void struct{}
12121313var member void
14141515-//Cpf type
1616-type Cpf string
1717-1818-func (c Cpf) String() string {
1919- return string(c)
2020-}
21152216func checksum(ds []int64) int64 {
2317 var s int64
···3125 return r
3226}
33273434-//IsValid checks whether Cpf number is valid or not
3535-func (c Cpf) IsValid() bool {
3636- u := c.Unmask()
2828+//IsValid checks whether CPF number is valid or not
2929+func IsValid(n string) bool {
3030+ u := Unmask(n)
37313832 if len(u) != 11 {
3933 return false
···5044 s[c] = member
5145 }
52465353- //If all digits are the same, the Cpf is not valid
4747+ //If all digits are the same, the CPF is not valid
5448 if len(s) == 1 {
5549 return false
5650 }
···5852 return checksum(ds[:9]) == ds[9] && checksum(ds[:10]) == ds[10]
5953}
60546161-//Mask returns the Cpf number formatted
6262-func (c Cpf) Mask() string {
6363- u := c.Unmask()
5555+//Mask returns the CPF number formatted
5656+func Mask(n string) string {
5757+ u := Unmask(n)
6458 if len(u) != 11 {
6565- return string(c)
5959+ return n
6660 }
6761 return fmt.Sprintf("%s.%s.%s-%s", u[:3], u[3:6], u[6:9], u[9:])
6862}
69637070-//Unmask removes any non-digit (numeric) from the Cpf
7171-func (c Cpf) Unmask() string {
7272- return regexp.MustCompile(`\D`).ReplaceAllString(string(c), "")
6464+//Unmask removes any non-digit (numeric) from the CPF number
6565+func Unmask(n string) string {
6666+ return regexp.MustCompile(`\D`).ReplaceAllString(n, "")
7367}