Skip to content

Commit

Permalink
bump versions (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
ringsaturn authored Dec 2, 2022
1 parent c2ce583 commit 1e89513
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 33 deletions.
15 changes: 15 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -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"
11 changes: 5 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -42,3 +40,4 @@ jobs:
run: |
golangci-lint run ./...
go test -race ./...
go test -bench=. ./...
6 changes: 4 additions & 2 deletions cmd/placekey/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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
)

Expand Down
13 changes: 9 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
27 changes: 9 additions & 18 deletions pk.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"strings"

"github.com/huandu/xstrings"
"github.com/uber/h3-go"
"github.com/uber/h3-go/v4"
)

const (
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}

Expand All @@ -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) {
Expand All @@ -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
Expand Down

0 comments on commit 1e89513

Please sign in to comment.