|
9 | 9 | "strconv"
|
10 | 10 | "time"
|
11 | 11 |
|
12 |
| - "github.com/grafana/datasource-http-backend/pkg/kinds" |
13 | 12 | "github.com/grafana/grafana-plugin-sdk-go/backend"
|
14 | 13 | "github.com/grafana/grafana-plugin-sdk-go/backend/datasource"
|
15 | 14 | "github.com/grafana/grafana-plugin-sdk-go/backend/httpclient"
|
@@ -75,6 +74,7 @@ var DatasourceOpts = datasource.ManageOpts{
|
75 | 74 | attribute.String("my_plugin.my_attribute", "custom value"),
|
76 | 75 | },
|
77 | 76 | },
|
| 77 | + QueryConversionHandler: backend.ConvertQueryFunc(convertQueryRequest), |
78 | 78 | }
|
79 | 79 |
|
80 | 80 | // Datasource is an example datasource which can respond to data queries, reports
|
@@ -174,13 +174,12 @@ func (d *Datasource) query(ctx context.Context, pCtx backend.PluginContext, quer
|
174 | 174 | return backend.DataResponse{}, fmt.Errorf("new request with context: %w", err)
|
175 | 175 | }
|
176 | 176 | if len(query.JSON) > 0 {
|
177 |
| - input := &kinds.DataQuery{} |
178 |
| - err = json.Unmarshal(query.JSON, input) |
| 177 | + input, err := convertQuery(query) |
179 | 178 | if err != nil {
|
180 |
| - return backend.DataResponse{}, fmt.Errorf("unmarshal: %w", err) |
| 179 | + return backend.DataResponse{}, err |
181 | 180 | }
|
182 | 181 | q := req.URL.Query()
|
183 |
| - q.Add("multiplier", strconv.Itoa(input.Multiplier)) |
| 182 | + q.Add("multiplier", strconv.Itoa(input.Multiply)) |
184 | 183 | req.URL.RawQuery = q.Encode()
|
185 | 184 | }
|
186 | 185 | httpResp, err := d.httpClient.Do(req)
|
|
0 commit comments