Skip to content

Commit 4607bd7

Browse files
committed
add some example code
1 parent 529d076 commit 4607bd7

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,63 @@ To include `cabrillo` into your own projects as a library:
99
```shell
1010
go get github.com/ftl/cabrillo
1111
```
12+
### Read a Cabrillo log file
13+
14+
```go
15+
f, err := os.Open("mycabrillo.log")
16+
if err != nil {
17+
panic(err)
18+
}
19+
log, err := cabrillo.Read(f)
20+
if err != nil {
21+
panic(err)
22+
}
23+
```
24+
25+
### Write a Cabrillo log file
26+
27+
```go
28+
log := cabrillo.NewLog()
29+
log.Contest = "CQ-WW-CW"
30+
log.Callsign = callsign.MustParse("DL0ABC")
31+
log.Operators = []callsign.Callsign{callsign.MustParse("DL1ABC")}
32+
log.Host = callsign.MustParse("DL1ABC")
33+
log.Location = "DX"
34+
log.Category.Operator = cabrillo.SingleOperator
35+
log.Category.Assisted = cabrillo.Assisted
36+
log.Category.Band = cabrillo.BandAll
37+
log.Category.Power = cabrillo.HighPower
38+
log.Category.Mode = cabrillo.ModeCW
39+
log.Category.Transmitter = cabrillo.OneTransmitter
40+
log.ClaimedScore = 12345
41+
log.Club = "Bavarian Contest Club"
42+
log.Name = "Hans Hamster"
43+
log.Email = "[email protected]"
44+
log.Address.Text = "Beispielstraße 1"
45+
log.Address.City = "Musterstadt"
46+
log.Address.Postalcode = "12345"
47+
log.Address.StateProvince = "Bavaria"
48+
log.Address.Country = "Germany"
49+
log.CreatedBy = "Golang Cabrillo Example"
50+
log.Soapbox = "this is just an example that shows how to write Cabrillo logs in Golang"
51+
52+
// qsos is where you keep your QSO data in your internal representation
53+
qsoData := make([]QSO, 0, len(qsos))
54+
for _, qso := range qsos {
55+
// convertQSOToCabrillo converts your internal represenation to cabrillo.QSO
56+
qsoData = append(qsoData, convertQSOToCabrillo(qso))
57+
}
58+
log.QSOData = qsoData
59+
60+
f, err := os.Create("mycabrillo.log")
61+
if err != nil {
62+
panic(err)
63+
}
64+
err = cabrillo.Write(f, log, false)
65+
if err != nil {
66+
panic(err)
67+
}
68+
```
1269

1370
## License
1471
This software is published under the [MIT License](https://www.tldrlegal.com/l/mit).

0 commit comments

Comments
 (0)