/* STACKIT IaaS API This API allows you to create and modify IaaS resources. API version: 2beta1 */ // Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. package iaasbeta import ( "encoding/json" "fmt" ) // RouteDestination - struct for RouteDestination type RouteDestination struct { DestinationCIDRv4 *DestinationCIDRv4 DestinationCIDRv6 *DestinationCIDRv6 } // DestinationCIDRv4AsRouteDestination is a convenience function that returns DestinationCIDRv4 wrapped in RouteDestination func DestinationCIDRv4AsRouteDestination(v *DestinationCIDRv4) RouteDestination { return RouteDestination{ DestinationCIDRv4: v, } } // DestinationCIDRv6AsRouteDestination is a convenience function that returns DestinationCIDRv6 wrapped in RouteDestination func DestinationCIDRv6AsRouteDestination(v *DestinationCIDRv6) RouteDestination { return RouteDestination{ DestinationCIDRv6: v, } } // Unmarshal JSON data into one of the pointers in the struct func (dst *RouteDestination) UnmarshalJSON(data []byte) error { var err error // use discriminator value to speed up the lookup var jsonDict map[string]interface{} err = newStrictDecoder(data).Decode(&jsonDict) if err != nil { return fmt.Errorf("failed to unmarshal JSON into map for the discriminator lookup") } // check if the discriminator value is 'DestinationCIDRv4' if jsonDict["type"] == "DestinationCIDRv4" { // try to unmarshal JSON data into DestinationCIDRv4 err = json.Unmarshal(data, &dst.DestinationCIDRv4) if err == nil { return nil // data stored in dst.DestinationCIDRv4, return on the first match } else { dst.DestinationCIDRv4 = nil return fmt.Errorf("failed to unmarshal RouteDestination as DestinationCIDRv4: %s", err.Error()) } } // check if the discriminator value is 'DestinationCIDRv6' if jsonDict["type"] == "DestinationCIDRv6" { // try to unmarshal JSON data into DestinationCIDRv6 err = json.Unmarshal(data, &dst.DestinationCIDRv6) if err == nil { return nil // data stored in dst.DestinationCIDRv6, return on the first match } else { dst.DestinationCIDRv6 = nil return fmt.Errorf("failed to unmarshal RouteDestination as DestinationCIDRv6: %s", err.Error()) } } // check if the discriminator value is 'cidrv4' if jsonDict["type"] == "cidrv4" { // try to unmarshal JSON data into DestinationCIDRv4 err = json.Unmarshal(data, &dst.DestinationCIDRv4) if err == nil { return nil // data stored in dst.DestinationCIDRv4, return on the first match } else { dst.DestinationCIDRv4 = nil return fmt.Errorf("failed to unmarshal RouteDestination as DestinationCIDRv4: %s", err.Error()) } } // check if the discriminator value is 'cidrv6' if jsonDict["type"] == "cidrv6" { // try to unmarshal JSON data into DestinationCIDRv6 err = json.Unmarshal(data, &dst.DestinationCIDRv6) if err == nil { return nil // data stored in dst.DestinationCIDRv6, return on the first match } else { dst.DestinationCIDRv6 = nil return fmt.Errorf("failed to unmarshal RouteDestination as DestinationCIDRv6: %s", err.Error()) } } return nil } // Marshal data from the first non-nil pointers in the struct to JSON func (src RouteDestination) MarshalJSON() ([]byte, error) { if src.DestinationCIDRv4 != nil { return json.Marshal(&src.DestinationCIDRv4) } if src.DestinationCIDRv6 != nil { return json.Marshal(&src.DestinationCIDRv6) } return []byte("{}"), nil // no data in oneOf schemas => empty JSON object } // Get the actual instance func (obj *RouteDestination) GetActualInstance() interface{} { if obj == nil { return nil } if obj.DestinationCIDRv4 != nil { return obj.DestinationCIDRv4 } if obj.DestinationCIDRv6 != nil { return obj.DestinationCIDRv6 } // all schemas are nil return nil } type NullableRouteDestination struct { value *RouteDestination isSet bool } func (v NullableRouteDestination) Get() *RouteDestination { return v.value } func (v *NullableRouteDestination) Set(val *RouteDestination) { v.value = val v.isSet = true } func (v NullableRouteDestination) IsSet() bool { return v.isSet } func (v *NullableRouteDestination) Unset() { v.value = nil v.isSet = false } func NewNullableRouteDestination(val *RouteDestination) *NullableRouteDestination { return &NullableRouteDestination{value: val, isSet: true} } func (v NullableRouteDestination) MarshalJSON() ([]byte, error) { return json.Marshal(v.value) } func (v *NullableRouteDestination) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) }