h3-go icon indicating copy to clipboard operation
h3-go copied to clipboard

Help with "Hello World" for `h3-go`

Open ajfriend opened this issue 1 year ago • 3 comments

I've never used go before, and I'm trying to get a simple "Hello world" example running.

I've run brew install go and I can run a simple example like this one (https://gobyexample.com/values) with go run values.go.

I'd like to get a similar example running with h3, but I'm getting stuck on package management.

Following the readme example, I have a file h3example.go:

package main

import "github.com/uber/h3-go/v4"

func main() {
 latLng := h3.NewLatLng(37.775938728915946, -122.41795063018799)
 resolution := 9 // between 0 (biggest cell) and 15 (smallest cell)

 cell := h3.LatLngToCell(latLng, resolution)

 fmt.Printf("%s", cell)
 // Output:
 // 8928308280fffff
}

I try running go get github.com/uber/h3-go/v4, but that redirects me to use go install instead, so I try

❯ go install github.com/uber/h3-go/v4@latest
package github.com/uber/h3-go/v4 is not a main package

But I can't tell if that did anything...

So then I try:

❯ go run h3example.go
h3example.go:3:8: no required module provides package github.com/uber/h3-go/v4: go.mod file not found in current directory or any parent directory; see 'go help modules'

I'm sure its simple, but any help would be appreciated!

ajfriend avatar Apr 27 '24 19:04 ajfriend

You will need to create a go.mod file alongside your h3example.go file. This can be achieved by running go mod init followed by go mod tidy. After running both of these you should end up with a tree structure like below:

├── go.mod
├── go.sum
└── h3example.go

With this in place you should then be able to run your example with go run h3example.go

retbrown avatar Apr 27 '24 19:04 retbrown

That worked. Thanks!

And if it is helpful for anyone else, here's a little example repo: https://github.com/ajfriend/h3llo_gorld

ajfriend avatar Apr 27 '24 20:04 ajfriend

Glad it's working for you. Perchance, can this issue be closed now?

zachcoleman avatar Jun 18 '24 21:06 zachcoleman