From 48415cdf7c75345d09aa3a3bc6aa46ed8f5a5b03 Mon Sep 17 00:00:00 2001 From: Caio Dallaqua <25767779+CaioDallaqua@users.noreply.github.com> Date: Tue, 11 Jan 2022 08:44:28 -0300 Subject: [PATCH 1/5] Update README.md --- README.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 981a19a..c3a099f 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,16 @@ -# Tile38 Client +# Tile38 Client for Go ⭐️ [![Go](https://github.com/xjem/t38c/workflows/Go/badge.svg)](https://github.com/xjem/t38c/actions) [![Documentation](https://pkg.go.dev/badge/github.com/xjem/t38c)](https://pkg.go.dev/github.com/xjem/t38c?tab=doc) [![Go Report Card](https://goreportcard.com/badge/github.com/xjem/t38c)](https://goreportcard.com/report/github.com/xjem/t38c) [![codecov](https://codecov.io/gh/xjem/t38c/branch/master/graph/badge.svg)](https://codecov.io/gh/xjem/t38c) [![license](https://img.shields.io/github/license/xjem/t38c.svg)](https://github.com/xjem/t38c/blob/master/LICENSE) -Supported features: [click](TODO.md) +See what [Tile38](https://tile38.com/) is all about. + +- [Supported features](TODO.md) :heavy_check_mark: +- [Examples](examples) :fire: + +### Installation ``` go get github.com/xjem/t38c @@ -54,4 +59,3 @@ func main() { fmt.Println(response.Points[0].ID, response.Points[0].Point) } ``` -More examples: [click](examples) From ebd742e2f7c9abf87effa810192079ddfbc8e755 Mon Sep 17 00:00:00 2001 From: CaioDallaqua Date: Tue, 11 Jan 2022 11:07:32 -0300 Subject: [PATCH 2/5] Adding flushdb --- client.go | 2 ++ server.go | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 server.go diff --git a/client.go b/client.go index a030932..a32291c 100644 --- a/client.go +++ b/client.go @@ -21,6 +21,7 @@ type Client struct { Channels *Channels Scripting *Scripting Geofence *Geofence + Server *Server } type clientParams struct { @@ -91,6 +92,7 @@ func NewWithExecutor(exec Executor, debug bool) (*Client, error) { client.Search = &Search{client} client.Scripting = &Scripting{client} client.Channels = &Channels{client} + client.Server = &Server{client} return client, nil } diff --git a/server.go b/server.go new file mode 100644 index 0000000..87b09bd --- /dev/null +++ b/server.go @@ -0,0 +1,19 @@ +package t38c + +type Server struct { + client tile38Client +} + +// WARNING: This erases all data in Tile38 DB! +func (sv *Server) FlushDB() error { + var resp struct{} + + err := sv.client.jExecute(&resp, "FLUSHDB") + + // Explicit is better than implicit. + if err != nil { + return err + } + + return nil +} From 62720da81871cb4a005c1bbb94d5b4c2e132bd9a Mon Sep 17 00:00:00 2001 From: CaioDallaqua Date: Tue, 11 Jan 2022 11:08:10 -0300 Subject: [PATCH 3/5] Adding flushdb example --- examples/flush_db.go | 61 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 examples/flush_db.go diff --git a/examples/flush_db.go b/examples/flush_db.go new file mode 100644 index 0000000..7181302 --- /dev/null +++ b/examples/flush_db.go @@ -0,0 +1,61 @@ +// +build ignore + +package main + +import ( + "log" + + "github.com/xjem/t38c" +) + +/* +* FLUSHDB Example +* +* Shows how to erase all data in Tile38 +* database using the FLUSHDB command. +* +*/ + +func main() { + // Variables to be used along the way. + var ( + err error + tile38 *t38c.Client + ) + + // Create a Tile38 client. + tile38, err = t38c.New("localhost:9851", t38c.Debug) + if err != nil { + log.Fatal(err) + } + defer tile38.Close() + + // Add a point named 'truck1' to a collection named 'first fleet'. + if err = tile38.Keys.Set("first fleet", "truck1").Point(33.5123, -112.2693).Do(); err != nil { + log.Fatal(err) + } + + // Add a point named 'truck2' to a collection named 'second fleet'. + if err = tile38.Keys.Set("second fleet", "truck2").Point(23.6951, -92.3581).Do(); err != nil { + log.Fatal(err) + } + + // Get all keys. + // Returns ["first fleet","second fleet"]. + _, err = tile38.Keys.Keys("*") + if err != nil { + log.Fatal(err) + } + + // Flush ALL data in Tile38 database. + if err = tile38.Server.FlushDB(); err != nil { + log.Fatal(err) + } + + // Get all keys again. + // Returns []. + _, err = tile38.Keys.Keys("*") + if err != nil { + log.Fatal(err) + } +} From 755035d485ea0041a668fc8d64ec00076aecd6f2 Mon Sep 17 00:00:00 2001 From: CaioDallaqua Date: Tue, 11 Jan 2022 11:09:16 -0300 Subject: [PATCH 4/5] Adding flushdb --- TODO.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TODO.md b/TODO.md index e520c4a..07fac17 100644 --- a/TODO.md +++ b/TODO.md @@ -178,7 +178,7 @@ # Group 'server' - [ ] CONFIG GET -- [ ] FLUSHDB +- [x] FLUSHDB - [ ] SERVER - [ ] READONLY - [ ] CONFIG REWRITE From a700318ebe067f17be84e44df7e0bf073c05e874 Mon Sep 17 00:00:00 2001 From: CaioDallaqua Date: Thu, 13 Jan 2022 20:26:25 -0300 Subject: [PATCH 5/5] Removing emojis from readme --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c3a099f..a9c4eb0 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Tile38 Client for Go ⭐️ +# Tile38 Client for Go [![Go](https://github.com/xjem/t38c/workflows/Go/badge.svg)](https://github.com/xjem/t38c/actions) [![Documentation](https://pkg.go.dev/badge/github.com/xjem/t38c)](https://pkg.go.dev/github.com/xjem/t38c?tab=doc) [![Go Report Card](https://goreportcard.com/badge/github.com/xjem/t38c)](https://goreportcard.com/report/github.com/xjem/t38c) @@ -7,8 +7,8 @@ See what [Tile38](https://tile38.com/) is all about. -- [Supported features](TODO.md) :heavy_check_mark: -- [Examples](examples) :fire: +- [Supported features](TODO.md) +- [Examples](examples) ### Installation