-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgedcom.go
51 lines (37 loc) · 871 Bytes
/
gedcom.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
package gedcom
import (
"bufio"
"errors"
"os"
"github.com/adamisrael/gedcom/parser"
"github.com/adamisrael/gedcom/types"
)
// How do I export types from types.* here as gedcom.Gedcom?
// OpenGedcom will open a filename, if it exists, and parse it as a GEDCOM
func OpenGedcom(filename string) (*types.Gedcom, error) {
if _, err := os.Stat(filename); err == nil {
f, err := os.Open(filename)
check(err)
defer f.Close()
p := parser.NewParser(bufio.NewReader(f))
g, err := p.Parse()
check(err)
return g, err
}
return nil, errors.New("invalid GEDCOM file")
}
// Gedcom is the main entrypoint
func Gedcom(gedcomFile string) *types.Gedcom {
f, err := os.Open(gedcomFile)
check(err)
defer f.Close()
p := parser.NewParser(bufio.NewReader(f))
g, err := p.Parse()
check(err)
return g
}
func check(e error) {
if e != nil {
panic(e)
}
}