Skip to content

Commit

Permalink
parse reponse in stream mode
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitryk-dk committed Feb 8, 2024
1 parent 12f71e9 commit bd726c6
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 13 deletions.
15 changes: 8 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,14 @@ app-via-docker-windows-amd64:
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 $(MAKE) app-via-docker-windows-goarch

victorialogs-backend-plugin-build: \
victorialogs-backend-plugin-linux-amd64-prod \
victorialogs-backend-plugin-linux-arm-prod \
victorialogs-backend-plugin-linux-arm64-prod \
victorialogs-backend-plugin-linux-386-prod \
victorialogs-backend-plugin-amd64-prod \
victorialogs-backend-plugin-arm64-prod \
victorialogs-backend-plugin-windows-prod
victorialogs-backend-plugin-amd64-prod
# victorialogs-backend-plugin-linux-amd64-prod \
# victorialogs-backend-plugin-linux-arm-prod \
# victorialogs-backend-plugin-linux-arm64-prod \
# victorialogs-backend-plugin-linux-386-prod \
# victorialogs-backend-plugin-arm64-prod \
# victorialogs-backend-plugin-windows-prod

victorialogs-frontend-plugin-build: \
frontend-build
Expand Down
29 changes: 25 additions & 4 deletions pkg/plugin/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,34 @@ func (d *Datasource) query(ctx context.Context, _ backend.PluginContext, query b
return newResponseError(err, backend.Status(resp.StatusCode))
}

// TODO implement correct response
var r interface{}
if err := json.NewDecoder(resp.Body).Decode(&r); err != nil {
err = fmt.Errorf("failed to decode body response: %w", err)
dec := json.NewDecoder(resp.Body)

t, err := dec.Token()
if err != nil {
return newResponseError(err, backend.StatusInternal)
}

if t != json.Delim('{') {
return newResponseError(fmt.Errorf("expected {, got %v", t), backend.StatusInternal)
}

for dec.More() {
var r Response
err := dec.Decode(&r)
if err != nil {
return newResponseError(err, backend.StatusInternal)
}

log.DefaultLogger.Info("RESPONSE => %#v", r)
}

// var r Response
// if err := json.NewDecoder(resp.Body).Decode(&r); err != nil {
// err = fmt.Errorf("failed to decode body response: %w", err)
// return newResponseError(err, backend.StatusInternal)
// }

// log.DefaultLogger.Info("RESPONSE => %#v", r)
// TODO convert response to the data Frames
// frames, err := r.getDataFrames()
// if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions pkg/plugin/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type Data struct {

// Response contains fields from query response
type Response struct {
Status string `json:"status"`
Data Data `json:"data"`
Message string `json:"_msg"`
Stream string `json:"_stream"`
Time string `json:"_time"`
}

0 comments on commit bd726c6

Please sign in to comment.