From 1e89513dc6c00a0c94750734f02ab7dcff5ccce1 Mon Sep 17 00:00:00 2001 From: ringsaturn Date: Sat, 3 Dec 2022 01:36:18 +0800 Subject: [PATCH] bump versions (#5) --- .github/dependabot.yml | 15 +++++++++++++++ .github/workflows/ci.yml | 11 +++++------ cmd/placekey/main.go | 6 ++++-- go.mod | 6 +++--- go.sum | 13 +++++++++---- pk.go | 27 +++++++++------------------ 6 files changed, 45 insertions(+), 33 deletions(-) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..41811b8 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,15 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: "gomod" # See documentation for possible values + directory: "/" # Location of package manifests + schedule: + interval: "daily" + - package-ecosystem: "github-actions" # See documentation for possible values + directory: "/" # Location of package manifests + schedule: + interval: "daily" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 44096eb..c60e0e5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,20 +9,18 @@ on: jobs: build: runs-on: ubuntu-latest - env: - GOPROXY: https://proxy.golang.org strategy: matrix: - go: ["1.17"] + go: ["1.19"] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Set up Go - uses: actions/setup-go@v2 + uses: actions/setup-go@v3 with: go-version: ${{ matrix.go }} - - uses: actions/cache@v2 + - uses: actions/cache@v3 with: path: | ~/.cache/go-build @@ -42,3 +40,4 @@ jobs: run: | golangci-lint run ./... go test -race ./... + go test -bench=. ./... diff --git a/cmd/placekey/main.go b/cmd/placekey/main.go index 26f5548..bf04169 100644 --- a/cmd/placekey/main.go +++ b/cmd/placekey/main.go @@ -8,8 +8,10 @@ import ( "github.com/ringsaturn/pk" ) -const FromGeoFlag = "FromGeo" -const ToGeoFlag = "ToGeo" +const ( + FromGeoFlag = "FromGeo" + ToGeoFlag = "ToGeo" +) func showErr() { fmt.Printf("expected '%v' or '%v' subcommands\n", FromGeoFlag, ToGeoFlag) diff --git a/go.mod b/go.mod index 225db7f..f9d568a 100644 --- a/go.mod +++ b/go.mod @@ -1,11 +1,11 @@ module github.com/ringsaturn/pk -go 1.17 +go 1.19 require ( - github.com/huandu/xstrings v1.3.2 + github.com/huandu/xstrings v1.4.0 github.com/ringsaturn/requests v0.1.0 - github.com/uber/h3-go v3.0.1+incompatible + github.com/uber/h3-go/v4 v4.0.1 go.uber.org/ratelimit v0.2.0 ) diff --git a/go.sum b/go.sum index 8e768aa..4add989 100644 --- a/go.sum +++ b/go.sum @@ -1,19 +1,24 @@ github.com/andres-erbsen/clock v0.0.0-20160526145045-9e14626cd129 h1:MzBOUgng9orim59UnfUTLRjMpd09C5uEVQ6RPGeCaVI= github.com/andres-erbsen/clock v0.0.0-20160526145045-9e14626cd129/go.mod h1:rFgpPQZYZ8vdbc+48xibu8ALc3yeyd64IhHS+PU6Yyg= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/huandu/xstrings v1.3.2 h1:L18LIDzqlW6xN2rEkpdV8+oL/IXWJ1APd+vsdYy4Wdw= -github.com/huandu/xstrings v1.3.2/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= +github.com/huandu/xstrings v1.4.0 h1:D17IlohoQq4UcpqD7fDk80P7l+lwAmlFaBHgOipl2FU= +github.com/huandu/xstrings v1.4.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/ringsaturn/requests v0.1.0 h1:3W152Lc80Man+V7AoeZamKhUiZEKuHZVfPWdzdVNJkM= github.com/ringsaturn/requests v0.1.0/go.mod h1:dq7MKwNyXr9AKHdNvUlpguFE9TJSdjdsAqN3NTQfsuI= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/uber/h3-go v3.0.1+incompatible h1:RVpBm8qd7mM94YuIhNQfCXpVj6mPY6gNsVstDg1FvjY= -github.com/uber/h3-go v3.0.1+incompatible/go.mod h1:66a2M4rQlf+dtkTWj3bHoLFgDT/Rt4kLT8dMuEQVQvw= +github.com/uber/h3-go/v4 v4.0.1 h1:eOcQXs+eC9Vmil0ZWicPYwSVfgwkPlMyk6Udm/kdv8w= +github.com/uber/h3-go/v4 v4.0.1/go.mod h1:VDpXVn4NLetBoISLEbiTVNstwW00bhHolV8I+jx9G+4= +go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/ratelimit v0.2.0 h1:UQE2Bgi7p2B85uP5dC2bbRtig0C+OeNRnNEafLjsLPA= go.uber.org/ratelimit v0.2.0/go.mod h1:YYBV4e4naJvhpitQrWJu1vCpgB7CboMe0qhltKt6mUg= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/pk.go b/pk.go index aaa0072..eca8077 100644 --- a/pk.go +++ b/pk.go @@ -22,7 +22,7 @@ import ( "strings" "github.com/huandu/xstrings" - "github.com/uber/h3-go" + "github.com/uber/h3-go/v4" ) const ( @@ -99,13 +99,7 @@ func zfill(rawString string, padString string, expectLength int) string { } func init_H3_HEADER() { - idx := strconv.FormatInt( - int64( - h3.FromGeo( - h3.GeoCoord{Latitude: 0, Longitude: 0}, - _RESOLUTION, - )), - 2) + idx := strconv.FormatInt(int64(h3.NewLatLng(0, 0).Cell(_RESOLUTION)), 2) // Python bin(xxx) result has prefix "0bxxxxx" // Golang FormatInt does not filled := zfill(idx, "0", 64) @@ -197,10 +191,7 @@ func GeoToPlacekey(lat, long float64) (string, error) { if lat < -90 || lat > 90 || long < -180 || long > 180 { return "", errors.New("invalid lat/long range") } - return encodeH3Int(int64(h3.FromGeo( - h3.GeoCoord{Latitude: lat, Longitude: long}, - _RESOLUTION, - ))), nil + return encodeH3Int(int64(h3.NewLatLng(lat, long).Cell(_RESOLUTION))), nil } func parsePlacekey(placekey string) (string, string, error) { @@ -251,13 +242,12 @@ func decodeToH3Int(wherePart string) int64 { } // PlacekeyToH3 convert placekey to H3 Index -func PlacekeyToH3(placekey string) (*h3.H3Index, error) { +func PlacekeyToH3(placekey string) (*h3.Cell, error) { _, where, err := parsePlacekey(placekey) if err != nil { return nil, err } - h3Int := decodeToH3Int(where) - idx := h3.FromString(strconv.FormatUint(uint64(h3Int), 16)) + idx := h3.Cell(decodeToH3Int(where)) return &idx, nil } @@ -267,8 +257,9 @@ func PlacekeyToGeo(placekey string) (float64, float64, error) { if err != nil { return 0, 0, err } - h3Idx := h3.ToGeo(*idx) - return h3Idx.Latitude, h3Idx.Longitude, nil + lat := idx.LatLng().Lat + lng := idx.LatLng().Lng + return lat, lng, nil } func PlacekeyDistance(pk1 string, pk2 string) (float64, error) { @@ -293,7 +284,7 @@ func validateWhere(where string) bool { if err != nil { return false } - return _WHERE_REGEX.MatchString(where) && h3.IsValid(*h) + return _WHERE_REGEX.MatchString(where) && h.IsValid() } // ValidatePlacekey will use Regex and H3 to