🇧🇷 CPF validation in Go

Merge pull request #1 from eminetto/master

feat: add comments recommended by golint

authored by

Eduardo Cuducos and committed by
GitHub
9f7ad50d 92ab4fe1

+4 -1
+4 -1
cpf.go
··· 7 7 "strings" 8 8 ) 9 9 10 + //Cpf type 10 11 type Cpf string 11 12 12 13 func (c Cpf) String() string { 13 14 return string(c) 14 15 } 15 16 17 + //Validate check if Cpf is in a valid format 16 18 func (c Cpf) Validate() bool { 17 - 18 19 toInt := func(chars []string) []int { 19 20 digits := make([]int, len(chars)) 20 21 for index, value := range chars { ··· 62 63 63 64 } 64 65 66 + //Mask return the formated value 65 67 func (c Cpf) Mask() string { 66 68 unmasked := c.Unmask() 67 69 if len(unmasked) < 11 { ··· 70 72 return fmt.Sprintf("%s.%s.%s-%s", unmasked[:3], unmasked[3:6], unmasked[6:9], unmasked[9:]) 71 73 } 72 74 75 + //Unmask remove format and return the raw data 73 76 func (c Cpf) Unmask() string { 74 77 pattern := regexp.MustCompile(`\D`) 75 78 unmasked := pattern.ReplaceAllString(c.String(), "")