tile38/client
Josh Baker 8d7290915e doc typos 2016-11-16 13:01:19 -07:00
..
README.md doc typos 2016-11-16 13:01:19 -07:00
conn.go lint cleanup 2016-04-02 19:16:36 -07:00
conn_test.go misspellings 2016-04-02 18:31:45 -07:00
helper.go lint cleanup 2016-04-02 19:16:36 -07:00
pool.go first commit 2016-03-04 16:08:16 -07:00
pool_test.go first commit 2016-03-04 16:08:16 -07:00

README.md

Tile38 Client

Build Status GoDoc

Tile38 Client is a Go client for Tile38.

Examples

Connection

package main

import "github.com/tidwall/tile38/client"

func main(){
    conn, err := client.Dial("localhost:9851")
    if err != nil {
        log.Fatal(err)
    }
    defer conn.Close()
    resp, err := conn.Do("set fleet truck1 point 33.5123 -112.2693")
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println(string(resp))
}

Pool

package main

import "github.com/tidwall/tile38/client"

func main(){
    pool, err := client.DialPool("localhost:9851")
    if err != nil {
        log.Fatal(err)
    }
    defer pool.Close()

    // We'll set a point in a background routine
    go func() {
        conn, err := pool.Get() // get a conn from the pool
        if err != nil {
            log.Fatal(err)
        }
        defer conn.Close() // return the conn to the pool
        _, err = conn.Do("set fleet truck1 point 33.5123 -112.2693")
        if err != nil {
            log.Fatal(err)
        }
    }()
    time.Sleep(time.Second / 2) // wait a moment

    // Retrieve the point we just set.
    go func() {
        conn, err := pool.Get() // get a conn from the pool
        if err != nil {
            log.Fatal(err)
        }
        defer conn.Close() // return the conn to the pool
        resp, err := conn.Do("get fleet truck1 point")
        if err != nil {
            log.Fatal(err)
        }
        fmt.Println(string(resp))
    }()
    time.Sleep(time.Second / 2) // wait a moment
}
```:q