mirror of
https://github.com/grafana/grafana.git
synced 2024-11-29 20:24:18 -06:00
4cd2575ad0
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
37 lines
752 B
Go
37 lines
752 B
Go
package pipeline
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
|
|
"github.com/grafana/grafana-plugin-sdk-go/data"
|
|
)
|
|
|
|
// JsonFrameConverter decodes single data.Frame from JSON.
|
|
type JsonFrameConverter struct {
|
|
config JsonFrameConverterConfig
|
|
}
|
|
|
|
func NewJsonFrameConverter(c JsonFrameConverterConfig) *JsonFrameConverter {
|
|
return &JsonFrameConverter{
|
|
config: c,
|
|
}
|
|
}
|
|
|
|
const ConverterTypeJsonFrame = "jsonFrame"
|
|
|
|
func (c *JsonFrameConverter) Type() string {
|
|
return ConverterTypeJsonFrame
|
|
}
|
|
|
|
func (c *JsonFrameConverter) Convert(_ context.Context, _ Vars, body []byte) ([]*ChannelFrame, error) {
|
|
var frame data.Frame
|
|
err := json.Unmarshal(body, &frame)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return []*ChannelFrame{
|
|
{Channel: "", Frame: &frame},
|
|
}, nil
|
|
}
|