-
Notifications
You must be signed in to change notification settings - Fork 1
/
nik_gen.go
57 lines (45 loc) · 1.22 KB
/
nik_gen.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
49
50
51
52
53
54
55
56
57
package nikparser
import (
"fmt"
"github.com/fanchann/nik-parser/functions"
"github.com/fanchann/nik-parser/models"
"github.com/fanchann/nik-parser/utils"
)
type NIKOpts struct {
District string
PostalCode string
Ttl int
}
func NIKGen(nikopts ...*NIKOpts) []string {
var niks []string
defaultTtl := 10
if len(nikopts) == 0 {
for i := 0; i < defaultTtl; i++ {
randomDistrict := utils.GetRandomNumberFromModel(models.District)
randomBirth := utils.GenRandomBirth()
randomStr := utils.GenRandomString()
nikData := fmt.Sprintf("%s%s%s", randomDistrict, randomBirth, randomStr)
niks = append(niks, nikData)
}
}
for _, opt := range nikopts {
district := utils.GetKeyByValue(models.District, fmt.Sprintf("%s -- %s", opt.District, opt.PostalCode))
if opt.Ttl == 0 {
opt.Ttl = 10
}
for i := 0; i < opt.Ttl; i++ {
nikData := fmt.Sprintf("%s%s%s", district, utils.GenRandomBirth(), utils.GenRandomString())
niks = append(niks, nikData)
}
}
var validNIK []string
// check nik is valid
checkNIK := new(functions.NIK)
for _, nik := range niks {
checkNIK.NIKNumber = nik
if err := checkNIK.ValidateNIK(); err == nil {
validNIK = append(validNIK, nik)
}
}
return validNIK
}