-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
54 lines (42 loc) · 1.04 KB
/
main.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
package main
import (
"errors"
"flag"
"fmt"
"log"
"sort"
)
const defaultDistance = 100.0 // in km
var fileName string
var distance float64
// parse parses available options and guards invalid options.
// As this is usually beginning of whole application, all failures will
// result in error message being displayed and exiting program.
func parse() error {
flag.StringVar(&fileName, "f", "", "Path of a file with list of guests")
flag.Float64Var(&distance, "d", defaultDistance,
"Distance in km, defaults to 100 km")
flag.Parse()
if fileName == "" {
return errors.New("File path must not be empty")
}
if distance < 0 {
return errors.New("Distance cannot be negative")
}
return nil
}
func main() {
if err := parse(); err != nil {
log.Fatal(err)
}
if guests, err := ReadGuestsList(fileName); err != nil {
log.Fatal(err)
} else {
inviteList := guests.FindGuestsWithinRange(
DublinLongitudeRad, DublinLatitudeRad, distance)
sort.Sort(inviteList)
for i, guest := range inviteList {
fmt.Println(i, guest)
}
}
}