package apiclient import ( "encoding/json" "fmt" "net/http" "github.com/AFASystems/presence/internal/pkg/config" "github.com/AFASystems/presence/internal/pkg/model" ) func GetTrackers(token string, client *http.Client, cfg *config.Config) ([]model.Tracker, error) { res, err := getRequest(token, "getTrackers", client, cfg) if err != nil { fmt.Printf("error get trackers: %+v\n", err) return []model.Tracker{}, err } var i []model.Tracker err = json.NewDecoder(res.Body).Decode(&i) if err != nil { fmt.Printf("error decode trackers: %+v\n", err) return []model.Tracker{}, err } return i, nil } func GetGateways(token string, client *http.Client, cfg *config.Config) ([]model.Gateway, error) { res, err := getRequest(token, "getGateways", client, cfg) if err != nil { fmt.Printf("error get gateways: %+v\n", err) return []model.Gateway{}, err } var i []model.Gateway err = json.NewDecoder(res.Body).Decode(&i) if err != nil { return []model.Gateway{}, err } return i, nil } func GetTrackerZones(token string, client *http.Client, cfg *config.Config) ([]model.TrackerZones, error) { res, err := getRequest(token, "getTrackerZones", client, cfg) if err != nil { return []model.TrackerZones{}, err } var i []model.TrackerZones err = json.NewDecoder(res.Body).Decode(&i) if err != nil { return []model.TrackerZones{}, err } return i, nil } func GetZones(token string, client *http.Client, cfg *config.Config) ([]model.Zone, error) { res, err := getRequest(token, "getZones", client, cfg) if err != nil { return []model.Zone{}, err } var i []model.Zone err = json.NewDecoder(res.Body).Decode(&i) if err != nil { return []model.Zone{}, err } return i, nil } func InferPosition(token string, client *http.Client, cfg *config.Config) (model.PositionResponse, error) { url := fmt.Sprintf("%s/ble-ai/infer", cfg.APIBaseURL) req, err := http.NewRequest("GET", url, nil) if err != nil { fmt.Printf("error new request: %+v\n", err) return model.PositionResponse{}, err } setHeader(req, token) res, err := client.Do(req) if err != nil { fmt.Printf("error do request: %+v\n", err) return model.PositionResponse{}, err } var i model.PositionResponse err = json.NewDecoder(res.Body).Decode(&i) if err != nil { fmt.Printf("error decode response: %+v\n", err) return model.PositionResponse{}, err } return i, nil }