bunnyshell.com/sdk@v0.16.0/model_environment_edit_settings_edit.go (about)

     1  /*
     2  API Bunnyshell Environments
     3  
     4  Interact with Bunnyshell Platform
     5  
     6  API version: 1.1.0
     7  Contact: osi+support@bunnyshell.com
     8  */
     9  
    10  // Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
    11  
    12  package sdk
    13  
    14  import (
    15  	"encoding/json"
    16  	"fmt"
    17  )
    18  
    19  // EnvironmentEditSettingsEdit - Environment edit by type
    20  type EnvironmentEditSettingsEdit struct {
    21  	Ephemeral *Ephemeral
    22  	Primary   *Primary
    23  }
    24  
    25  // EphemeralAsEnvironmentEditSettingsEdit is a convenience function that returns Ephemeral wrapped in EnvironmentEditSettingsEdit
    26  func EphemeralAsEnvironmentEditSettingsEdit(v *Ephemeral) EnvironmentEditSettingsEdit {
    27  	return EnvironmentEditSettingsEdit{
    28  		Ephemeral: v,
    29  	}
    30  }
    31  
    32  // PrimaryAsEnvironmentEditSettingsEdit is a convenience function that returns Primary wrapped in EnvironmentEditSettingsEdit
    33  func PrimaryAsEnvironmentEditSettingsEdit(v *Primary) EnvironmentEditSettingsEdit {
    34  	return EnvironmentEditSettingsEdit{
    35  		Primary: v,
    36  	}
    37  }
    38  
    39  // Unmarshal JSON data into one of the pointers in the struct
    40  func (dst *EnvironmentEditSettingsEdit) UnmarshalJSON(data []byte) error {
    41  	var err error
    42  	match := 0
    43  	// try to unmarshal data into Ephemeral
    44  	err = json.Unmarshal(data, &dst.Ephemeral)
    45  	if err == nil {
    46  		jsonEphemeral, _ := json.Marshal(dst.Ephemeral)
    47  		if string(jsonEphemeral) == "{}" { // empty struct
    48  			dst.Ephemeral = nil
    49  		} else {
    50  			match++
    51  		}
    52  	} else {
    53  		dst.Ephemeral = nil
    54  	}
    55  
    56  	// try to unmarshal data into Primary
    57  	err = json.Unmarshal(data, &dst.Primary)
    58  	if err == nil {
    59  		jsonPrimary, _ := json.Marshal(dst.Primary)
    60  		if string(jsonPrimary) == "{}" { // empty struct
    61  			dst.Primary = nil
    62  		} else {
    63  			match++
    64  		}
    65  	} else {
    66  		dst.Primary = nil
    67  	}
    68  
    69  	if match > 1 { // more than 1 match
    70  		// reset to nil
    71  		dst.Ephemeral = nil
    72  		dst.Primary = nil
    73  
    74  		return fmt.Errorf("data matches more than one schema in oneOf(EnvironmentEditSettingsEdit)")
    75  	} else if match == 1 {
    76  		return nil // exactly one match
    77  	} else { // no match
    78  		return fmt.Errorf("data failed to match schemas in oneOf(EnvironmentEditSettingsEdit)")
    79  	}
    80  }
    81  
    82  // Marshal data from the first non-nil pointers in the struct to JSON
    83  func (src EnvironmentEditSettingsEdit) MarshalJSON() ([]byte, error) {
    84  	if src.Ephemeral != nil {
    85  		return json.Marshal(&src.Ephemeral)
    86  	}
    87  
    88  	if src.Primary != nil {
    89  		return json.Marshal(&src.Primary)
    90  	}
    91  
    92  	return nil, nil // no data in oneOf schemas
    93  }
    94  
    95  // Get the actual instance
    96  func (obj *EnvironmentEditSettingsEdit) GetActualInstance() interface{} {
    97  	if obj == nil {
    98  		return nil
    99  	}
   100  	if obj.Ephemeral != nil {
   101  		return obj.Ephemeral
   102  	}
   103  
   104  	if obj.Primary != nil {
   105  		return obj.Primary
   106  	}
   107  
   108  	// all schemas are nil
   109  	return nil
   110  }
   111  
   112  type NullableEnvironmentEditSettingsEdit struct {
   113  	value *EnvironmentEditSettingsEdit
   114  	isSet bool
   115  }
   116  
   117  func (v NullableEnvironmentEditSettingsEdit) Get() *EnvironmentEditSettingsEdit {
   118  	return v.value
   119  }
   120  
   121  func (v *NullableEnvironmentEditSettingsEdit) Set(val *EnvironmentEditSettingsEdit) {
   122  	v.value = val
   123  	v.isSet = true
   124  }
   125  
   126  func (v NullableEnvironmentEditSettingsEdit) IsSet() bool {
   127  	return v.isSet
   128  }
   129  
   130  func (v *NullableEnvironmentEditSettingsEdit) Unset() {
   131  	v.value = nil
   132  	v.isSet = false
   133  }
   134  
   135  func NewNullableEnvironmentEditSettingsEdit(val *EnvironmentEditSettingsEdit) *NullableEnvironmentEditSettingsEdit {
   136  	return &NullableEnvironmentEditSettingsEdit{value: val, isSet: true}
   137  }
   138  
   139  func (v NullableEnvironmentEditSettingsEdit) MarshalJSON() ([]byte, error) {
   140  	return json.Marshal(v.value)
   141  }
   142  
   143  func (v *NullableEnvironmentEditSettingsEdit) UnmarshalJSON(src []byte) error {
   144  	v.isSet = true
   145  	return json.Unmarshal(src, &v.value)
   146  }