go-whenami is a package that provides functionality to lookup the timezone of a given coordinate.
import (
"log"
"github.com/nlittlepoole/go-whenami"
)
func main(){
lat := -77.0283 // float64
long := 38.389 // float64
timezone, err = whenami.WhenAmI(lat, long)
if err != nil{
log.Warn(err)
}
}This is a port of the Python project tzgeo. You can use this library to quickly associate a timezone with an (Latitude, Longitude) coordinate. In particular, this is helpful when parsing server or CDN logs that don't have timezone information but have coordinates provided via GeoIP.
I've included a small REST microservice built with the Gin framework. It exposes two endpoints. The first is a health check endpoint
for scenarios where youy want to host this in a production system. The second is a /whenami/ GET endpoint that takes latitude and longitude
as query parameters. It returns the timezone and any encountered errors.
I've also created a Dockerfile that can be used to build spatialite and golang on top of Alpine. The container I've written also runs the server but feel free to rip any of that ode for another purpose.
- Self host the tzgeo.sqlite file
- Add tests
- Create a base container for Spatialite + Golang on Alpine
