aboutsummaryrefslogtreecommitdiff
path: root/src/example.go
diff options
context:
space:
mode:
authorPacien TRAN-GIRARD2014-09-30 22:07:44 +0200
committerPacien TRAN-GIRARD2014-09-30 22:07:44 +0200
commit1be0cb5a3fa5b2abe5f5d10ec827f06617861d4b (patch)
tree4ef98c2982834af152cd4b57a16d310e8635be0e /src/example.go
parent67b03424e3aee09078dff50cbf9d3e9e4221bc93 (diff)
downloadgo-vparse-master.tar.gz
First versionHEADmaster
Diffstat (limited to 'src/example.go')
-rw-r--r--src/example.go31
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 @@
1package main
2
3import (
4 "encoding/json"
5 "fmt"
6 "os"
7 "vparse"
8)
9
10func check(err error) {
11 if err != nil {
12 panic(err)
13 }
14}
15
16func 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
28func main() {
29 fmt.Println(vToJson("vcal.ics"))
30 fmt.Println(vToJson("vcard.vcs"))
31}