tile38/cmd/tile38-cli/internal/client/conn_test.go

58 lines
1.1 KiB
Go
Raw Permalink Normal View History

2016-03-06 18:57:11 +03:00
package client
import (
"fmt"
"log"
"time"
)
func ExampleDial() {
conn, err := 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))
}
func ExampleDialPool() {
pool, err := 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
2016-04-03 04:31:45 +03:00
// Retrieve the point we just set.
2016-03-06 18:57:11 +03:00
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
}