/
go.go
48 lines (39 loc) · 871 Bytes
/
go.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package validators
import (
"strconv"
)
// GO struct - Goias
// Implements the Validator interface
type GO struct {
}
// IsValid func
func (v GO) IsValid(insc string) bool {
rule := NewRule()
if !rule.IsCorrectSize(insc, 9) {
return false
}
if !rule.IsStartWith(insc, "10") && !rule.IsStartWith(insc, "11") && !rule.IsStartWith(insc, "15") {
return false
}
base := rule.GetBaseValue(insc, 0)
if base == "11094402" {
var udigit = insc[:len(insc)-1]
return udigit == "1" || udigit == "0"
}
weights := rule.GetWeight(9, 8)
total := rule.CalculateTotal(insc, 8, weights)
rest := rule.CalculateMod(total, 11)
var digit string
if rest == 0 {
digit = "0"
} else if rest == 1 {
if rule.Between(base, 10103105, 10119997) {
digit = "1"
} else {
digit = "0"
}
} else {
digit = strconv.Itoa(11 - rest)
}
return insc == base+digit
}