t38c icon indicating copy to clipboard operation
t38c copied to clipboard

Keys.Get output format

Open aureliensibiril opened this issue 2 years ago • 3 comments

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.

aureliensibiril avatar Mar 15 '22 15:03 aureliensibiril

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.

shadowspore avatar Mar 15 '22 16:03 shadowspore

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.

SamiAlsubhi avatar Mar 24 '22 04:03 SamiAlsubhi

@aureliensibiril please try v0.10.0

shadowspore avatar Aug 26 '22 15:08 shadowspore

@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)
}

shadowspore avatar Nov 14 '22 03:11 shadowspore

Closing as resolved. Feel free to reopen this issue or create a new one if you encounter some problems.

shadowspore avatar Nov 14 '22 03:11 shadowspore