From 7f1bb18fd654b58eae56b1d02c4568d62ff226a5 Mon Sep 17 00:00:00 2001 From: Alexander Kiryukhin Date: Mon, 17 Aug 2020 13:19:06 +0300 Subject: initial --- main.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 main.go (limited to 'main.go') diff --git a/main.go b/main.go new file mode 100644 index 0000000..349f41c --- /dev/null +++ b/main.go @@ -0,0 +1,45 @@ +package main + +import ( + "github.com/labstack/echo/v4" + "log" + "strconv" +) + +func main() { + e := echo.New() + e.GET("/map", func(c echo.Context) error { + lat, err := strconv.ParseFloat(c.QueryParam("lat"), 64) + if err != nil { + return err + } + lon, err := strconv.ParseFloat(c.QueryParam("lon"), 64) + if err != nil { + return err + } + w, err := strconv.Atoi(c.QueryParam("w")) + if err != nil { + w = 800 + } + h, err := strconv.Atoi(c.QueryParam("h")) + if err != nil { + h = 800 + } + zoom, err := strconv.Atoi(c.QueryParam("zoom")) + if err != nil { + zoom = 16 + } + if zoom < 1 { + zoom = 1 + } + if zoom > 20 { + zoom = 20 + } + img, err := GetMapImage(lat, lon, zoom, w, h) + if err != nil { + return err + } + return c.Blob(200, "image/png", img) + }) + log.Fatal(e.Start(":8000")) +} -- cgit v1.2.3