diff --git a/README.md b/README.md index 981a19a..a9c4eb0 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) +- [Examples](examples) + +### 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) 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 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/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) + } +} 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 +}