terraform-provider-stackitp.../pkg/cdnbeta/model_config_backend.go
2026-01-21 09:07:29 +01:00

163 lines
4.1 KiB
Go

/*
CDN API
API used to create and manage your CDN distributions.
API version: 1beta2.0.0
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package cdnbeta
import (
"encoding/json"
"fmt"
)
// ConfigBackend - struct for ConfigBackend
type ConfigBackend struct {
BucketBackend *BucketBackend
HttpBackend *HttpBackend
}
// BucketBackendAsConfigBackend is a convenience function that returns BucketBackend wrapped in ConfigBackend
func BucketBackendAsConfigBackend(v *BucketBackend) ConfigBackend {
return ConfigBackend{
BucketBackend: v,
}
}
// HttpBackendAsConfigBackend is a convenience function that returns HttpBackend wrapped in ConfigBackend
func HttpBackendAsConfigBackend(v *HttpBackend) ConfigBackend {
return ConfigBackend{
HttpBackend: v,
}
}
// Unmarshal JSON data into one of the pointers in the struct
func (dst *ConfigBackend) 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 'BucketBackend'
if jsonDict["type"] == "BucketBackend" {
// try to unmarshal JSON data into BucketBackend
err = json.Unmarshal(data, &dst.BucketBackend)
if err == nil {
return nil // data stored in dst.BucketBackend, return on the first match
} else {
dst.BucketBackend = nil
return fmt.Errorf("failed to unmarshal ConfigBackend as BucketBackend: %s", err.Error())
}
}
// check if the discriminator value is 'HttpBackend'
if jsonDict["type"] == "HttpBackend" {
// try to unmarshal JSON data into HttpBackend
err = json.Unmarshal(data, &dst.HttpBackend)
if err == nil {
return nil // data stored in dst.HttpBackend, return on the first match
} else {
dst.HttpBackend = nil
return fmt.Errorf("failed to unmarshal ConfigBackend as HttpBackend: %s", err.Error())
}
}
// check if the discriminator value is 'bucket'
if jsonDict["type"] == "bucket" {
// try to unmarshal JSON data into BucketBackend
err = json.Unmarshal(data, &dst.BucketBackend)
if err == nil {
return nil // data stored in dst.BucketBackend, return on the first match
} else {
dst.BucketBackend = nil
return fmt.Errorf("failed to unmarshal ConfigBackend as BucketBackend: %s", err.Error())
}
}
// check if the discriminator value is 'http'
if jsonDict["type"] == "http" {
// try to unmarshal JSON data into HttpBackend
err = json.Unmarshal(data, &dst.HttpBackend)
if err == nil {
return nil // data stored in dst.HttpBackend, return on the first match
} else {
dst.HttpBackend = nil
return fmt.Errorf("failed to unmarshal ConfigBackend as HttpBackend: %s", err.Error())
}
}
return nil
}
// Marshal data from the first non-nil pointers in the struct to JSON
func (src ConfigBackend) MarshalJSON() ([]byte, error) {
if src.BucketBackend != nil {
return json.Marshal(&src.BucketBackend)
}
if src.HttpBackend != nil {
return json.Marshal(&src.HttpBackend)
}
return []byte("{}"), nil // no data in oneOf schemas => empty JSON object
}
// Get the actual instance
func (obj *ConfigBackend) GetActualInstance() interface{} {
if obj == nil {
return nil
}
if obj.BucketBackend != nil {
return obj.BucketBackend
}
if obj.HttpBackend != nil {
return obj.HttpBackend
}
// all schemas are nil
return nil
}
type NullableConfigBackend struct {
value *ConfigBackend
isSet bool
}
func (v NullableConfigBackend) Get() *ConfigBackend {
return v.value
}
func (v *NullableConfigBackend) Set(val *ConfigBackend) {
v.value = val
v.isSet = true
}
func (v NullableConfigBackend) IsSet() bool {
return v.isSet
}
func (v *NullableConfigBackend) Unset() {
v.value = nil
v.isSet = false
}
func NewNullableConfigBackend(val *ConfigBackend) *NullableConfigBackend {
return &NullableConfigBackend{value: val, isSet: true}
}
func (v NullableConfigBackend) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *NullableConfigBackend) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}