-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
63 lines (50 loc) · 1.32 KB
/
main.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
58
59
60
61
62
63
package main
import (
"fmt"
"io/ioutil"
"log"
"os"
"strconv"
"strings"
"github.com/buger/jsonparser"
)
func main() {
var nik int
fmt.Print("Input NIK: ")
_, err := fmt.Scanf("%d", &nik)
if err != nil {
log.Fatal("NIK Tidak Valid")
}
nikstr := strconv.Itoa(nik)
if len(nikstr) != 16 {
log.Fatal("NIK Tidak Valid")
}
tanggal := nikstr[6:8]
bulan := nikstr[8:10]
tahun := nikstr[10:12]
provinsi := nikstr[0:2]
kabkot := nikstr[0:4]
kecamatan := nikstr[0:6]
uniqcode := nikstr[12:16]
jeniskelamin := "LAKI-LAKI"
cekjk, _ := strconv.Atoi(nikstr[6:8])
if cekjk > 40 {
jeniskelamin = "PEREMPUAN"
}
data, err := os.Open("data.json")
defer data.Close()
if err != nil {
log.Fatal("Data Tidak Valid")
}
byteValue, _ := ioutil.ReadAll(data)
provinsi, _ = jsonparser.GetString(byteValue, "provinsi", provinsi)
kabkot, _ = jsonparser.GetString(byteValue, "kabkot", kabkot)
kecamatan, _ = jsonparser.GetString(byteValue, "kecamatan", kecamatan)
fmt.Printf("Tanggal Lahir: %s/%s/%s\n", tanggal, bulan, tahun)
fmt.Printf("Jenis Kelamin: %s\n", jeniskelamin)
fmt.Printf("Provinsi: %s\n", provinsi)
fmt.Printf("Kab/Kota: %s\n", kabkot)
fmt.Printf("Kecamatan: %s\n", strings.Split(kecamatan, "--")[0])
fmt.Printf("Kode Pos: %s\n", strings.Split(kecamatan, "--")[1])
fmt.Printf("Uniqcode: %s\n", uniqcode)
}