t38c
t38c copied to clipboard
Keys.Get output format
Hi,
I'm trying to retrieve a point in the Point output format. To do so, I tried to force a bit the Keys.Get without success, I found a way around but I am under the impression that this is not a good solution.
Tile.Keys.Set("fleet", "truck1").Point(61.76543034, 37.67770367).Do()
// ==> [SET fleet truck1 POINT 61.76543034 37.67770367]: {"ok":true,"elapsed":"775.125µs"}
// This Fail
q, err := Tile.Keys.Get("fleet", "truck1"+" POINT", false)
// ==> [GET fleet truck1 POINT]: {"ok":false,"err":"id not found","elapsed":"35.208µs"}
// This works
q, err := Tile.Execute("GET", "fleet", "truck1", "POINT")
// ==> [GET fleet truck1 POINT]: {"ok":true,"point":{"lat":61.76543034,"lon":37.67770367},"elapsed":"373.291µs"}
resp := t38c.GetResponse{}
json.Unmarshal(q, &resp)
I can't get to understand why it failed when the two commands look exactly the same.
Hey
The problem seems to be in the "truck1"+"POINT"
argument.
The Get
method does not support the format specification, and you are trying to pass it through the object identifier string.
This is why the server returns id not found
.
I will add format parameter support for this method soon.
I think there is an issue with TileClient.Keys.Get("key","id", true)
. It returns a result but without lat and lon. There are nil
. so I resorted to TileClient.Execute("GET", "key", "id", "POINT")
which works.
@aureliensibiril please try v0.10.0
@SamiAlsubhi I rewrote api a bit, and everything seems to be working fine:
package main
import (
"context"
"encoding/json"
"fmt"
"log"
"github.com/xjem/t38c"
)
func main() {
tile38, err := t38c.New(t38c.Config{
Address: "localhost:9851",
Debug: true,
})
if err != nil {
log.Fatal(err)
}
defer tile38.Close()
if err := tile38.Keys.Set("fleet", "truck1").Point(1, 2).Do(context.TODO()); err != nil {
log.Fatal(err)
}
truck1, err := tile38.Keys.Get("fleet", "truck1").Point(context.TODO())
if err != nil {
log.Fatal(err)
}
// truck1: {"point":{"lat":1,"lon":2},"fields":null}
printJSON("truck1", truck1)
}
func printJSON(msg string, data interface{}) {
b, _ := json.Marshal(data)
fmt.Printf("%s: %s\n", msg, b)
}
Closing as resolved. Feel free to reopen this issue or create a new one if you encounter some problems.