Future-proofing query and data source model in Dashboard Schema v2 (#104194)
--------- Signed-off-by: Igor Suleymanov <igor.suleymanov@grafana.com> Co-authored-by: alexandra vargas <alexa1866@gmail.com> Co-authored-by: Haris Rozajac <haris.rozajac12@gmail.com> Co-authored-by: Dominik Prokop <dominik.prokop@grafana.com> Co-authored-by: Igor Suleymanov <igor.suleymanov@grafana.com> Co-authored-by: spinillos <selenepinillos@gmail.com>
This commit is contained in:
co-authored by
alexandra vargas
Haris Rozajac
Dominik Prokop
Igor Suleymanov
spinillos
parent
cfa05a63c5
commit
075770070e
@@ -13,6 +13,7 @@ package dataquery
|
||||
|
||||
import (
|
||||
json "encoding/json"
|
||||
fmt "fmt"
|
||||
)
|
||||
|
||||
type AzureMonitorQuery struct {
|
||||
@@ -835,3 +836,58 @@ type StringOrBoolOrFloat64OrSelectableValue struct {
|
||||
func NewStringOrBoolOrFloat64OrSelectableValue() *StringOrBoolOrFloat64OrSelectableValue {
|
||||
return &StringOrBoolOrFloat64OrSelectableValue{}
|
||||
}
|
||||
|
||||
// MarshalJSON implements a custom JSON marshalling logic to encode `StringOrBoolOrFloat64OrSelectableValue` as JSON.
|
||||
func (resource StringOrBoolOrFloat64OrSelectableValue) MarshalJSON() ([]byte, error) {
|
||||
if resource.String != nil {
|
||||
return json.Marshal(resource.String)
|
||||
}
|
||||
if resource.Bool != nil {
|
||||
return json.Marshal(resource.Bool)
|
||||
}
|
||||
if resource.Float64 != nil {
|
||||
return json.Marshal(resource.Float64)
|
||||
}
|
||||
if resource.SelectableValue != nil {
|
||||
return json.Marshal(resource.SelectableValue)
|
||||
}
|
||||
|
||||
return []byte("null"), nil
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements a custom JSON unmarshalling logic to decode StringOrBoolOrFloat64OrSelectableValue from JSON.
|
||||
func (resource *StringOrBoolOrFloat64OrSelectableValue) UnmarshalJSON(raw []byte) error {
|
||||
if raw == nil {
|
||||
return nil
|
||||
}
|
||||
fields := make(map[string]json.RawMessage)
|
||||
if err := json.Unmarshal(raw, &fields); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if fields["String"] != nil {
|
||||
if err := json.Unmarshal(fields["String"], &resource.String); err != nil {
|
||||
return fmt.Errorf("error decoding field 'String': %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
if fields["Bool"] != nil {
|
||||
if err := json.Unmarshal(fields["Bool"], &resource.Bool); err != nil {
|
||||
return fmt.Errorf("error decoding field 'Bool': %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
if fields["Float64"] != nil {
|
||||
if err := json.Unmarshal(fields["Float64"], &resource.Float64); err != nil {
|
||||
return fmt.Errorf("error decoding field 'Float64': %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
if fields["SelectableValue"] != nil {
|
||||
if err := json.Unmarshal(fields["SelectableValue"], &resource.SelectableValue); err != nil {
|
||||
return fmt.Errorf("error decoding field 'SelectableValue': %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user