Skip to content

Commit 77f0f3c

Browse files
cmiller01codingsince1985
authored andcommitted
go vet + go vet fixups (#42)
1 parent 46e9b79 commit 77f0f3c

File tree

10 files changed

+31
-28
lines changed

10 files changed

+31
-28
lines changed

bing/geocoder.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ type (
3535
// Geocoder constructs Bing geocoder
3636
func Geocoder(key string, baseURLs ...string) geo.Geocoder {
3737
return geo.HTTPGeocoder{
38-
EndpointBuilder: baseURL(getUrl(key, baseURLs...)),
38+
EndpointBuilder: baseURL(getURL(key, baseURLs...)),
3939
ResponseParserFactory: func() geo.ResponseParser { return &geocodeResponse{} },
4040
}
4141
}
4242

43-
func getUrl(key string, baseURLs ...string) string {
43+
func getURL(key string, baseURLs ...string) string {
4444
if len(baseURLs) > 0 {
4545
return baseURLs[0]
4646
}

examples/geocoder_example.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@ import (
2020
const (
2121
addr = "Melbourne VIC"
2222
lat, lng = -37.813611, 144.963056
23-
RADIUS = 50
24-
ZOOM = 18
23+
radius = 50
24+
zoom = 18
2525
)
2626

2727
func main() {
2828
ExampleGeocoder()
2929
}
3030

31+
// ExampleGeocoder demonstrates the different geocoding services
3132
func ExampleGeocoder() {
3233
fmt.Println("Google Geocoding API")
3334
try(google.Geocoder(os.Getenv("GOOGLE_API_KEY")))
@@ -42,7 +43,7 @@ func ExampleGeocoder() {
4243
try(opencage.Geocoder(os.Getenv("OPENCAGE_API_KEY")))
4344

4445
fmt.Println("HERE API")
45-
try(here.Geocoder(os.Getenv("HERE_APP_ID"), os.Getenv("HERE_APP_CODE"), RADIUS))
46+
try(here.Geocoder(os.Getenv("HERE_APP_ID"), os.Getenv("HERE_APP_CODE"), radius))
4647

4748
fmt.Println("Bing Geocoding API")
4849
try(bing.Geocoder(os.Getenv("BING_API_KEY")))
@@ -54,7 +55,7 @@ func ExampleGeocoder() {
5455
try(openstreetmap.Geocoder())
5556

5657
fmt.Println("LocationIQ")
57-
try(locationiq.Geocoder(os.Getenv("LOCATIONIQ_API_KEY"), ZOOM))
58+
try(locationiq.Geocoder(os.Getenv("LOCATIONIQ_API_KEY"), zoom))
5859

5960
// Chained geocoder will fallback to subsequent geocoders
6061
fmt.Println("ChainedAPI[OpenStreetmap -> Google]")

google/geocoder.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type (
1818
Location geo.Location
1919
}
2020
}
21-
Status string `json: "status"`
21+
Status string `json:"status"`
2222
}
2323
googleAddressComponent struct {
2424
LongName string `json:"long_name"`
@@ -43,12 +43,12 @@ const (
4343
// Geocoder constructs Google geocoder
4444
func Geocoder(apiKey string, baseURLs ...string) geo.Geocoder {
4545
return geo.HTTPGeocoder{
46-
EndpointBuilder: baseURL(getUrl(apiKey, baseURLs...)),
46+
EndpointBuilder: baseURL(getURL(apiKey, baseURLs...)),
4747
ResponseParserFactory: func() geo.ResponseParser { return &geocodeResponse{} },
4848
}
4949
}
5050

51-
func getUrl(apiKey string, baseURLs ...string) string {
51+
func getURL(apiKey string, baseURLs ...string) string {
5252
if len(baseURLs) > 0 {
5353
return baseURLs[0]
5454
}

here/geocoder.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ type (
3939
}
4040
)
4141

42+
// Key*Name represents constants for geocoding more address detail
4243
const (
4344
KeyCountryName = "CountryName"
4445
KeyStateName = "StateName"
@@ -55,20 +56,20 @@ func Geocoder(id, code string, radius int, baseURLs ...string) geo.Geocoder {
5556
p := "gen=9&app_id=" + id + "&app_code=" + code
5657
return geo.HTTPGeocoder{
5758
EndpointBuilder: baseURL{
58-
getGeocodeUrl(p, baseURLs...),
59-
getReverseGeocodeUrl(p, baseURLs...)},
59+
getGeocodeURL(p, baseURLs...),
60+
getReverseGeocodeURL(p, baseURLs...)},
6061
ResponseParserFactory: func() geo.ResponseParser { return &geocodeResponse{} },
6162
}
6263
}
6364

64-
func getGeocodeUrl(p string, baseURLs ...string) string {
65+
func getGeocodeURL(p string, baseURLs ...string) string {
6566
if len(baseURLs) > 0 {
6667
return baseURLs[0]
6768
}
6869
return "http://geocoder.api.here.com/6.2/geocode.json?" + p
6970
}
7071

71-
func getReverseGeocodeUrl(p string, baseURLs ...string) string {
72+
func getReverseGeocodeURL(p string, baseURLs ...string) string {
7273
if len(baseURLs) > 0 {
7374
return baseURLs[0]
7475
}

http_geocoder.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"time"
1313
)
1414

15-
// Default timeout for the request execution
15+
// DefaultTimeout for the request execution
1616
const DefaultTimeout = time.Second * 8
1717

1818
// ErrTimeout occurs when no response returned within timeoutInSeconds
@@ -141,6 +141,7 @@ func response(ctx context.Context, url string, obj ResponseParser) error {
141141
return nil
142142
}
143143

144+
// ParseFloat is a helper to parse a string to a float
144145
func ParseFloat(value string) float64 {
145146
f, _ := strconv.ParseFloat(value, 64)
146147
return f

locationiq/geocoder_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ func TestGeocodeYieldsResult(t *testing.T) {
2222
}
2323

2424
if expLat != l.Lat {
25-
t.Errorf("Expected latitude: %s, got %s", expLat, l.Lat)
25+
t.Errorf("Expected latitude: %f, got %f", expLat, l.Lat)
2626
}
2727

2828
if expLon != l.Lng {
29-
t.Errorf("Expected longitude %s, got %s", expLon, l.Lng)
29+
t.Errorf("Expected longitude %f, got %f", expLon, l.Lng)
3030
}
3131
}
3232

mapbox/geocoder.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ const (
3737
// Geocoder constructs Mapbox geocoder
3838
func Geocoder(token string, baseURLs ...string) geo.Geocoder {
3939
return geo.HTTPGeocoder{
40-
EndpointBuilder: baseURL(getUrl(token, baseURLs...)),
40+
EndpointBuilder: baseURL(getURL(token, baseURLs...)),
4141
ResponseParserFactory: func() geo.ResponseParser { return &geocodeResponse{} },
4242
}
4343
}
4444

45-
func getUrl(token string, baseURLs ...string) string {
45+
func getURL(token string, baseURLs ...string) string {
4646
if len(baseURLs) > 0 {
4747
return baseURLs[0]
4848
}
@@ -60,9 +60,9 @@ func (r *geocodeResponse) Location() (*geo.Location, error) {
6060
// error in response
6161
if r.Message != "" {
6262
return nil, fmt.Errorf("reverse geocoding error: %s", r.Message)
63-
} else { // no results
64-
return nil, nil
6563
}
64+
// no results
65+
return nil, nil
6666
}
6767

6868
g := r.Features[0]
@@ -77,9 +77,9 @@ func (r *geocodeResponse) Address() (*geo.Address, error) {
7777
// error in response
7878
if r.Message != "" {
7979
return nil, fmt.Errorf("reverse geocoding error: %s", r.Message)
80-
} else { // no results
81-
return nil, nil
8280
}
81+
// no results
82+
return nil, nil
8383
}
8484

8585
return parseMapboxResponse(r), nil

mapquest/nominatim/geocoder.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ var key string
2525
func Geocoder(k string, baseURLs ...string) geo.Geocoder {
2626
key = k
2727
return geo.HTTPGeocoder{
28-
EndpointBuilder: baseURL(getUrl(baseURLs...)),
28+
EndpointBuilder: baseURL(getURL(baseURLs...)),
2929
ResponseParserFactory: func() geo.ResponseParser { return &geocodeResponse{} },
3030
}
3131
}
3232

33-
func getUrl(baseURLs ...string) string {
33+
func getURL(baseURLs ...string) string {
3434
if len(baseURLs) > 0 {
3535
return baseURLs[0]
3636
}

mapquest/open/geocoder.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ type (
3333
func Geocoder(key string, baseURLs ...string) geo.Geocoder {
3434

3535
return geo.HTTPGeocoder{
36-
EndpointBuilder: baseURL(getUrl(key, baseURLs...)),
36+
EndpointBuilder: baseURL(getURL(key, baseURLs...)),
3737
ResponseParserFactory: func() geo.ResponseParser { return &geocodeResponse{} },
3838
}
3939
}
4040

41-
func getUrl(key string, baseURLs ...string) string {
41+
func getURL(key string, baseURLs ...string) string {
4242
if len(baseURLs) > 0 {
4343
return baseURLs[0]
4444
}

opencage/geocoder.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ type (
2828
// Geocoder constructs OpenCage geocoder
2929
func Geocoder(key string, baseURLs ...string) geo.Geocoder {
3030
return geo.HTTPGeocoder{
31-
EndpointBuilder: baseURL(getUrl(key, baseURLs...)),
31+
EndpointBuilder: baseURL(getURL(key, baseURLs...)),
3232
ResponseParserFactory: func() geo.ResponseParser { return &geocodeResponse{} },
3333
}
3434
}
3535

36-
func getUrl(key string, baseURLs ...string) string {
36+
func getURL(key string, baseURLs ...string) string {
3737
if len(baseURLs) > 0 {
3838
return baseURLs[0]
3939
}

0 commit comments

Comments
 (0)