Sign inSign up

ringsaturn/tzf-server

By ringsaturn

•Updated about 2 years ago

Simple server convert longitude&latitude to timezone name

Image
0

8.3K

ringsaturn/tzf-server repository overview

⁠Simple server convert longitude&latitude to timezone name

Note

It's designed as a debugger tool for package tzf⁠, not production ready.

⁠Quick Start

⁠Install
⁠Install via go install
go install github.com/ringsaturn/tzf-server@latest
⁠Download from release page

Please visit https://github.com/ringsaturn/tzf-server/releases⁠ to get latest release.

⁠Install from Docker Hub⁠
docker pull ringsaturn/tzf-server
⁠Usage
Usage of tzf-server:
  -disable-print-route
        Disable Print Route
  -hertz-prometheus-host-port string
        Hertz Prometheus Host&Port (default "0.0.0.0:8090")
  -hertz-prometheus-path string
        Hertz Prometheus Path (default "/hertz")
  -http-addr string
        HTTP Host&Port (default "0.0.0.0:8080")
  -path string
        custom data
  -prometheus-enable-go-coll
        Enable Go Collector (default true)
  -prometheus-host-port string
        Prometheus Host&Port (default "0.0.0.0:2112")
  -prometheus-path string
        Prometheus Path (default "/metrics")
  -redis-addr string
        Redis Server Host&Port (default "localhost:6380")
  -type int
        which finder to use Polygon(0) or Fuzzy(1)

For example, start DefaultFinder⁠ server:

tzf-server

Or start FuzzyFinder⁠ based server:

tzf-server -type 1

⁠Web Pages

⁠All supported timezone names

http://localhost:8080/web/tzs/all⁠

⁠[Experiment] Clickable debugger

http://localhost:8080/web/click⁠

I have little knowledge about frontend development so it's just a experiment, most codes are written by ChatGPT 3.5. You can access the prompts from gist⁠.

⁠HTTP API

A swagger UI can be found at http://localhost:8080/swagger/index.html⁠.

⁠Lookup Location's timezone
curl "http://localhost:8080/api/v1/tz?longitude=116.3883&latitude=39.9289"

Output:

{
  "timezone": "Asia/Shanghai",
  "abbreviation": "CST",
  "offset": "28800s"
}
⁠Lookup Location's timezones
curl "http://localhost:8080/api/v1/tzs?longitude=87.6168&latitude=43.8254"

Output:

{
  "timezones": [
    {
      "timezone": "Asia/Shanghai",
      "abbreviation": "CST",
      "offset": "28800s"
    },
    {
      "timezone": "Asia/Urumqi",
      "abbreviation": "+06",
      "offset": "21600s"
    }
  ]
}
⁠All supported timezone names
curl "http://localhost:8080/api/v1/tzs/all"

Output:

{
  "timezones": [
    {
      "timezone": "Africa/Abidjan",
      "abbreviation": "GMT",
      "offset": "0s"
    },
    // ...
    {
      "timezone": "Etc/GMT+12",
      "abbreviation": "-12",
      "offset": "-43200s"
    }
  ]
}

⁠Redis Protocol Commands

⁠redis-cli
$ redis-cli -p 6380
127.0.0.1:6380> GET_TZ 116.3883 39.9289
Asia/Shanghai
127.0.0.1:6380> GET_TZS 87.4160 44.0400
1) "Asia/Shanghai"
2) "Asia/Urumqi"
⁠redis-py
>>> from redis import Redis
>>> rc = Redis.from_url("redis://localhost:6380")
>>> rc.ping()
True
>>> rc.execute_command("get_tz", 116.3883, 39.9289).decode()
'Asia/Shanghai'
>>> rc.execute_command("get_tzs", 87.4160, 44.0400)
[b'Asia/Shanghai', b'Asia/Urumqi']

Tag summary

Content type

Image

Digest

sha256:af1d7035a…

Size

82.8 MB

Last updated

about 2 years ago

docker pull ringsaturn/tzf-server