diff options
author | Pacien TRAN-GIRARD | 2014-09-30 22:07:44 +0200 |
---|---|---|
committer | Pacien TRAN-GIRARD | 2014-09-30 22:07:44 +0200 |
commit | 1be0cb5a3fa5b2abe5f5d10ec827f06617861d4b (patch) | |
tree | 4ef98c2982834af152cd4b57a16d310e8635be0e /src/example.go | |
parent | 67b03424e3aee09078dff50cbf9d3e9e4221bc93 (diff) | |
download | go-vparse-master.tar.gz |
Diffstat (limited to 'src/example.go')
-rw-r--r-- | src/example.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/example.go b/src/example.go new file mode 100644 index 0000000..9196336 --- /dev/null +++ b/src/example.go | |||
@@ -0,0 +1,31 @@ | |||
1 | package main | ||
2 | |||
3 | import ( | ||
4 | "encoding/json" | ||
5 | "fmt" | ||
6 | "os" | ||
7 | "vparse" | ||
8 | ) | ||
9 | |||
10 | func check(err error) { | ||
11 | if err != nil { | ||
12 | panic(err) | ||
13 | } | ||
14 | } | ||
15 | |||
16 | func vToJson(filename string) string { | ||
17 | f, err := os.Open(filename) | ||
18 | check(err) | ||
19 | |||
20 | parsed := vparse.Parse(f) | ||
21 | |||
22 | jsonEncoded, err := json.MarshalIndent(parsed, "", "\t") | ||
23 | check(err) | ||
24 | |||
25 | return string(jsonEncoded) | ||
26 | } | ||
27 | |||
28 | func main() { | ||
29 | fmt.Println(vToJson("vcal.ics")) | ||
30 | fmt.Println(vToJson("vcard.vcs")) | ||
31 | } | ||