model_timeseries_config_expression.go•4.19 kB
/*
Metoro Alerts API
API for managing alerts in the Metoro observability platform.
API version: 1.0.0
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package model
import (
"encoding/json"
"fmt"
"gopkg.in/validator.v2"
)
// TimeseriesConfigExpression - Expression defining the metrics to monitor
type TimeseriesConfigExpression struct {
ExpressionConfig *ExpressionConfig
String *string
}
// ExpressionConfigAsTimeseriesConfigExpression is a convenience function that returns ExpressionConfig wrapped in TimeseriesConfigExpression
func ExpressionConfigAsTimeseriesConfigExpression(v *ExpressionConfig) TimeseriesConfigExpression {
return TimeseriesConfigExpression{
ExpressionConfig: v,
}
}
// stringAsTimeseriesConfigExpression is a convenience function that returns string wrapped in TimeseriesConfigExpression
func StringAsTimeseriesConfigExpression(v *string) TimeseriesConfigExpression {
return TimeseriesConfigExpression{
String: v,
}
}
// Unmarshal JSON data into one of the pointers in the struct
func (dst *TimeseriesConfigExpression) UnmarshalJSON(data []byte) error {
var err error
match := 0
// try to unmarshal data into ExpressionConfig
err = newStrictDecoder(data).Decode(&dst.ExpressionConfig)
if err == nil {
jsonExpressionConfig, _ := json.Marshal(dst.ExpressionConfig)
if string(jsonExpressionConfig) == "{}" { // empty struct
dst.ExpressionConfig = nil
} else {
if err = validator.Validate(dst.ExpressionConfig); err != nil {
dst.ExpressionConfig = nil
} else {
match++
}
}
} else {
dst.ExpressionConfig = nil
}
// try to unmarshal data into String
err = newStrictDecoder(data).Decode(&dst.String)
if err == nil {
jsonString, _ := json.Marshal(dst.String)
if string(jsonString) == "{}" { // empty struct
dst.String = nil
} else {
if err = validator.Validate(dst.String); err != nil {
dst.String = nil
} else {
match++
}
}
} else {
dst.String = nil
}
if match > 1 { // more than 1 match
// reset to nil
dst.ExpressionConfig = nil
dst.String = nil
return fmt.Errorf("data matches more than one schema in oneOf(TimeseriesConfigExpression)")
} else if match == 1 {
return nil // exactly one match
} else { // no match
return fmt.Errorf("data failed to match schemas in oneOf(TimeseriesConfigExpression)")
}
}
// Marshal data from the first non-nil pointers in the struct to JSON
func (src TimeseriesConfigExpression) MarshalJSON() ([]byte, error) {
if src.ExpressionConfig != nil {
return json.Marshal(&src.ExpressionConfig)
}
if src.String != nil {
return json.Marshal(&src.String)
}
return nil, nil // no data in oneOf schemas
}
// Get the actual instance
func (obj *TimeseriesConfigExpression) GetActualInstance() (interface{}) {
if obj == nil {
return nil
}
if obj.ExpressionConfig != nil {
return obj.ExpressionConfig
}
if obj.String != nil {
return obj.String
}
// all schemas are nil
return nil
}
// Get the actual instance value
func (obj TimeseriesConfigExpression) GetActualInstanceValue() (interface{}) {
if obj.ExpressionConfig != nil {
return *obj.ExpressionConfig
}
if obj.String != nil {
return *obj.String
}
// all schemas are nil
return nil
}
type NullableTimeseriesConfigExpression struct {
value *TimeseriesConfigExpression
isSet bool
}
func (v NullableTimeseriesConfigExpression) Get() *TimeseriesConfigExpression {
return v.value
}
func (v *NullableTimeseriesConfigExpression) Set(val *TimeseriesConfigExpression) {
v.value = val
v.isSet = true
}
func (v NullableTimeseriesConfigExpression) IsSet() bool {
return v.isSet
}
func (v *NullableTimeseriesConfigExpression) Unset() {
v.value = nil
v.isSet = false
}
func NewNullableTimeseriesConfigExpression(val *TimeseriesConfigExpression) *NullableTimeseriesConfigExpression {
return &NullableTimeseriesConfigExpression{value: val, isSet: true}
}
func (v NullableTimeseriesConfigExpression) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *NullableTimeseriesConfigExpression) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}