grafana/pkg/services/live/pipeline/converter_json_frame.go
Alexander Emelin 4cd2575ad0
Live: generate ts definitions for pipeline configs (#41544)
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
2021-11-15 22:45:35 +03:00

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
}