-
Notifications
You must be signed in to change notification settings - Fork 10
/
encoder_example.go
141 lines (124 loc) · 2.58 KB
/
encoder_example.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
//go:build ignore
// run this using go run encoder_example.go
package main
import (
"log"
"os"
"github.com/iand/gedcom"
)
func main() {
g := new(gedcom.Gedcom)
sub := &gedcom.SubmitterRecord{
Xref: "SUBM",
Name: "John Doe",
}
g.Submitter = append(g.Submitter, sub)
g.Header = &gedcom.Header{
SourceSystem: gedcom.SystemRecord{
Xref: "gedcom",
SourceName: "github.com/iand/gedcom",
},
Submitter: sub,
CharacterSet: "UTF-8",
Language: "English",
Version: "5.5.1",
Form: "LINEAGE-LINKED",
}
// Define the family record
family := &gedcom.FamilyRecord{
Xref: "F1",
}
// Add the family to the GEDCOM
g.Family = append(g.Family, family)
// Define the father individual record
father := &gedcom.IndividualRecord{
Xref: "I1",
Name: []*gedcom.NameRecord{
{
Name: "John /Doe/",
},
},
Sex: "M",
Event: []*gedcom.EventRecord{
{
Tag: "BIRT",
Date: "1 JAN 1950",
Place: gedcom.PlaceRecord{
Name: "London, England",
},
},
},
}
// Add the father to the GEDCOM
g.Individual = append(g.Individual, father)
// Add the father to the family
family.Husband = father
// Define the mother individual record
mother := &gedcom.IndividualRecord{
Xref: "I2",
Name: []*gedcom.NameRecord{
{
Name: "Jane /Smith/",
},
},
Sex: "F",
Event: []*gedcom.EventRecord{
{
Tag: "BIRT",
Date: "5 MAY 1952",
Place: gedcom.PlaceRecord{
Name: "Manchester, England",
},
},
},
}
// Add the mother to the GEDCOM
g.Individual = append(g.Individual, mother)
// Add the mother to the family
family.Wife = mother
// Create individual record for a child
child := &gedcom.IndividualRecord{
Xref: "I3",
Name: []*gedcom.NameRecord{
{
Name: "Michael /Doe/",
},
},
Sex: "M",
Event: []*gedcom.EventRecord{
{
Tag: "BIRT",
Date: "15 JUL 1980",
Place: gedcom.PlaceRecord{
Name: "London, England",
},
},
},
// Link child to the family
Parents: []*gedcom.FamilyLinkRecord{
{
Family: family,
Type: "CHIL",
},
},
}
// Add the child to the GEDCOM
g.Individual = append(g.Individual, child)
// Add the child to the family
family.Child = append(family.Child, child)
// Add an event to the family
family.Event = append(family.Event, &gedcom.EventRecord{
Tag: "MARR",
Date: "10 JUN 1975",
Place: gedcom.PlaceRecord{
Name: "London, England",
},
},
)
g.Trailer = &gedcom.Trailer{}
enc := gedcom.NewEncoder(os.Stdout)
if err := enc.Encode(g); err != nil {
log.Fatalf("failed to encode gedcom: %v", err)
return
}
}