Skip to content

Commit 1e0e3d7

Browse files
committed
Merge pull request #4 from maxmind/greg/fix-for-updated-deps
Fixes for the major breaking API changes in the ipaddr module we use
2 parents 05e0f80 + 7ba5b3f commit 1e0e3d7

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ language: go
44
go:
55
- '1.2'
66
- '1.3'
7+
- '1.4'
8+
- '1.5'
9+
- release
710
- tip
811
notifications:
912
email:

convert/convert.go

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
)
1212

1313
type headerFunc func([]string) []string
14-
type lineFunc func(ipaddr.Prefix, []string) []string
14+
type lineFunc func(*ipaddr.Prefix, []string) []string
1515

1616
// ConvertFile converts the MaxMind GeoIP2 or GeoLite2 CSV file `inputFile` to
1717
// `outputFile` file using a different representation of the network. The
@@ -53,7 +53,7 @@ func Convert(
5353
) error {
5454

5555
makeHeader := func(orig []string) []string { return orig }
56-
makeLine := func(_ ipaddr.Prefix, orig []string) []string { return orig }
56+
makeLine := func(_ *ipaddr.Prefix, orig []string) []string { return orig }
5757

5858
if intRange {
5959
makeHeader = addHeaderFunc(makeHeader, intRangeHeader)
@@ -80,7 +80,7 @@ func addHeaderFunc(first headerFunc, second headerFunc) headerFunc {
8080
}
8181

8282
func addLineFunc(first lineFunc, second lineFunc) lineFunc {
83-
return func(network ipaddr.Prefix, line []string) []string {
83+
return func(network *ipaddr.Prefix, line []string) []string {
8484
return second(network, first(network, line))
8585
}
8686
}
@@ -89,17 +89,17 @@ func cidrHeader(orig []string) []string {
8989
return append([]string{"network"}, orig...)
9090
}
9191

92-
func cidrLine(network ipaddr.Prefix, orig []string) []string {
92+
func cidrLine(network *ipaddr.Prefix, orig []string) []string {
9393
return append([]string{network.String()}, orig...)
9494
}
9595

9696
func rangeHeader(orig []string) []string {
9797
return append([]string{"network_start_ip", "network_last_ip"}, orig...)
9898
}
9999

100-
func rangeLine(network ipaddr.Prefix, orig []string) []string {
100+
func rangeLine(network *ipaddr.Prefix, orig []string) []string {
101101
return append(
102-
[]string{network.Addr().String(), network.LastAddr().String()},
102+
[]string{network.IP.String(), network.Last().String()},
103103
orig...,
104104
)
105105
}
@@ -108,19 +108,27 @@ func intRangeHeader(orig []string) []string {
108108
return append([]string{"network_start_integer", "network_last_integer"}, orig...)
109109
}
110110

111-
func intRangeLine(network ipaddr.Prefix, orig []string) []string {
111+
func intRangeLine(network *ipaddr.Prefix, orig []string) []string {
112112
startInt := new(big.Int)
113-
startInt.SetBytes(network.Addr())
113+
114+
startInt.SetBytes(canonicalizeIP(network.IP))
114115

115116
endInt := new(big.Int)
116-
endInt.SetBytes(network.LastAddr())
117+
endInt.SetBytes(canonicalizeIP(network.Last()))
117118

118119
return append(
119120
[]string{startInt.String(), endInt.String()},
120121
orig...,
121122
)
122123
}
123124

125+
func canonicalizeIP(ip net.IP) net.IP {
126+
if v4 := ip.To4(); v4 != nil {
127+
return v4
128+
}
129+
return ip
130+
}
131+
124132
func convert(
125133
input io.Reader,
126134
output io.Writer,
@@ -163,11 +171,10 @@ func convert(
163171
return nil
164172
}
165173

166-
func makePrefix(network string) (ipaddr.Prefix, error) {
174+
func makePrefix(network string) (*ipaddr.Prefix, error) {
167175
_, ipn, err := net.ParseCIDR(network)
168176
if err != nil {
169177
return nil, err
170178
}
171-
nbits, _ := ipn.Mask.Size()
172-
return ipaddr.NewPrefix(ipn.IP, nbits)
179+
return ipaddr.NewPrefix(ipn), nil
173180
}

dev-bin/package.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@ do
3030
done
3131

3232
git tag -a $VERSION
33-
git push -u --tags
33+
git push --tags
34+
git push -u

0 commit comments

Comments
 (0)