-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
44 lines (41 loc) · 851 Bytes
/
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
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
)
func check(e error) {
if e != nil {
panic(e)
}
}
func append() {
errRemove := os.Remove("data.ln")
check(errRemove)
f, err := os.OpenFile("data.ln", os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)
check(err)
defer f.Close()
f.WriteString("[")
for i := 0; i < 1000; i++ {
if i == 999 {
if _, err = f.WriteString(fmt.Sprintf("{\"id\":%d, \"descript\":\"Test-%d\"}", i+1, i+1)); err != nil {
panic(err)
}
continue
}
if _, err = f.WriteString(fmt.Sprintf("{\"id\":%d, \"descript\":\"Test-%d\"},", i+1, i+1)); err != nil {
panic(err)
}
}
f.WriteString("]")
}
func main() {
append()
dat, err := ioutil.ReadFile("data.ln")
check(err)
var types []interface{}
errUnmarshal := json.Unmarshal(dat, &types)
check(errUnmarshal)
fmt.Printf("%+v", types)
}