diff --git a/.gitignore b/.gitignore index d48c759..e2ca916 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,6 @@ .idea -.vscode \ No newline at end of file +.vscode + +/public + +!/public/.gitkeep \ No newline at end of file diff --git a/main.go b/main.go index 49f2269..5f71f8b 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,7 @@ import ( "github.com/go-redis/redis" "github.com/supanadit/geosmartsystem/model" "github.com/supanadit/geosmartsystem/model/tile38" + "net/http" ) func main() { @@ -23,15 +24,21 @@ func main() { c.JSON(200, gin.H{"status": "ok"}) }) r.GET("/stream", func(c *gin.Context) { - writer := c.Writer - writer.Header().Set("Content-Type", "text/event-stream") - writer.Header().Set("Cache-Control", "no-cache") - writer.Header().Set("Connection", "keep-alive") - data, _ := tile38.FromScan(client, "sales") - _ = sse.Encode(writer, sse.Event{ - Event: "message", - Data: data, - }) + w := c.Writer + t := c.DefaultQuery("type", "user") + r := c.DefaultQuery("request", "") + data, _ := tile38.FromScan(client, t) + if r == "sse" { + w.Header().Set("Content-Type", "text/event-stream") + w.Header().Set("Cache-Control", "no-cache") + w.Header().Set("Connection", "keep-alive") + _ = sse.Encode(w, sse.Event{ + Event: "message", + Data: data, + }) + } else { + c.JSON(http.StatusOK, data) + } }) r.Static("/public", "./public") _ = r.Run() diff --git a/model/Location.go b/model/location.go similarity index 100% rename from model/Location.go rename to model/location.go diff --git a/public/.gitkeep b/public/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/public/index.html b/public/index.html deleted file mode 100644 index cae2355..0000000 --- a/public/index.html +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - -

- - - -