-
Notifications
You must be signed in to change notification settings - Fork 0
/
lookup.go
75 lines (58 loc) · 1.55 KB
/
lookup.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
package firststreet
import (
"errors"
"strconv"
)
// Lookup determines which type of lookup to request to the API service
type Lookup struct {
FSID string
Lat float64
Lng float64
Address string
}
// LookupType describes which type of lookup to use
type LookupType string
const FSIDLookup = LookupType("fsid")
const AddressLookup = LookupType("address")
const CoordinateLookup = LookupType("coordinate")
type LocationType string
const PropertyLocationType = LocationType("property")
const CityLocationType = LocationType("city")
// FSIDIsValid returns true if FSID is not ""
func (l *Lookup) FSIDIsValid() bool {
return l.FSID != ""
}
// Address is valid if address is not empty
func (l *Lookup) AddressIsValid() bool {
return l.Address != ""
}
// LatLngIsValid returns true if lat and lng are not 0
func (l *Lookup) LatLngIsValid() bool {
return l.Lat != 0 || l.Lng != 0
}
// LatLngString provides Lat or Lng as a string value
func (l *Lookup) LatLngString(latlng string) string {
if !l.LatLngIsValid() {
return ""
}
if latlng == "lat" {
return strconv.FormatFloat(l.Lat, 'f', -1, 64)
}
if latlng == "lng" {
return strconv.FormatFloat(l.Lng, 'f', -1, 64)
}
return ""
}
// LookupType returns the requested lookup type
func (l *Lookup) LookupType() (LookupType, error) {
if l.FSIDIsValid() {
return FSIDLookup, nil
}
if l.LatLngIsValid() {
return CoordinateLookup, nil
}
if l.AddressIsValid() {
return AddressLookup, nil
}
return "", errors.New("Lookup type could not be determined: Expecting an FSID, Lat and Lng, or Address.")
}