···11-name: Tests
22-33-on: [pull_request, push]
44-55-jobs:
66-77- build:
88- name: Build
99- runs-on: ubuntu-latest
1010- steps:
1111-1212- - name: Set up Go 1.14
1313- uses: actions/setup-go@v1
1414- with:
1515- go-version: 1.14
1616- id: go
1717-1818- - name: Check out code into the Go module directory
1919- uses: actions/checkout@v2
2020-2121- - name: Get dependencies
2222- run: |
2323- go get -v -t -d ./...
2424- if [ -f Gopkg.toml ]; then
2525- curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
2626- dep ensure
2727- fi
2828-2929- - name: Build
3030- run: go test
+15
.tangled/workflows/tests.yaml
···11+when:
22+ - event: ["push"]
33+ branch: ["main"]
44+engine: "nixery"
55+dependencies:
66+ nixpkgs:
77+ - go
88+ - golangci-lint
99+steps:
1010+ - name: Formatting
1111+ command: if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then exit 1; fi
1212+ - name: Linter
1313+ command: golangci-lint run ./...
1414+ - name: Tests
1515+ command: go test -v -race ./...
+2-2
README.md
···11-# Go CPF []()[](https://godoc.org/github.com/cuducos/go-cpf)
11+# Go CPF [](https://godoc.org/tangled.org/cuducos.me/go-cpf)
2233A Go module to validate CPF numbers (Brazilian unique identifier for the Federal Revenue).
4455```go
66package main
7788-import "github.com/cuducos/go-cpf"
88+import "tangled.org/cuducos.me/go-cpf"
9910101111func main() {
+7-8
cpf.go
···77 "strings"
88)
991010-//These are 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
1414-15141615func checksum(ds []int64) int64 {
1716 var s int64
···2524 return r
2625}
27262828-//IsValid checks whether CPF number is valid or not
2929-func IsValid(n string) bool {
2727+// IsValid checks whether CPF number is valid or not
2828+func IsValid(n string) bool {
3029 u := Unmask(n)
31303231 if len(u) != 11 {
···5251 return checksum(ds[:9]) == ds[9] && checksum(ds[:10]) == ds[10]
5352}
54535555-//Mask returns the CPF number formatted
5656-func Mask(n string) string {
5454+// Mask returns the CPF number formatted
5555+func Mask(n string) string {
5756 u := Unmask(n)
5857 if len(u) != 11 {
5958 return n
···6160 return fmt.Sprintf("%s.%s.%s-%s", u[:3], u[3:6], u[6:9], u[9:])
6261}
63626464-//Unmask removes any non-digit (numeric) from the CPF number
6565-func Unmask(n string) string {
6363+// Unmask removes any non-digit (numeric) from the CPF number
6464+func Unmask(n string) string {
6665 return regexp.MustCompile(`\D`).ReplaceAllString(n, "")
6766}