-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
50 lines (41 loc) · 869 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
45
46
47
48
49
50
package main
import (
"C"
"encoding/csv"
"log"
"os"
)
func toCsv(filename, data string) {
_, err := os.Stat(filename)
if err != nil {
file, err := os.Create(filename)
if err != nil {
log.Fatal(err)
}
defer file.Close()
}
file, err := os.OpenFile(filename, os.O_APPEND|os.O_WRONLY, os.ModeAppend)
if err != nil {
log.Fatal(err)
}
defer file.Close()
var csvdata [][]string
csvdata = append(csvdata, []string{data})
w := csv.NewWriter(file)
w.WriteAll(csvdata)
if err := w.Error(); err != nil {
log.Fatal(err)
}
}
func main() {
toCsv("admin.csv", "admins")
toCsv("admin.csv", "admins")
toCsv("admin.csv", "admins")
toCsv("admin.csv", "admins")
toCsv("admin.csv", "admins")
toCsv("admin.csv", "admins")
toCsv("admin.csv", "admins")
toCsv("admin.csv", "admins")
toCsv("admin.csv", "admins")
toCsv("admin.csv", "admins")
}