github.com/DaAlbrecht/cf-cli@v0.0.0-20231128151943-1fe19bb400b9/types/optional_string.go (about)

     1  package types
     2  
     3  import (
     4  	"encoding/json"
     5  )
     6  
     7  type OptionalString struct {
     8  	IsSet bool
     9  	Value string
    10  }
    11  
    12  func NewOptionalString(v string) OptionalString {
    13  	return OptionalString{
    14  		IsSet: true,
    15  		Value: v,
    16  	}
    17  }
    18  
    19  func (o *OptionalString) UnmarshalJSON(rawJSON []byte) error {
    20  	o.IsSet = true
    21  	return json.Unmarshal(rawJSON, &o.Value)
    22  }
    23  
    24  func (o OptionalString) MarshalJSON() ([]byte, error) {
    25  	return json.Marshal(o.Value)
    26  }
    27  
    28  func (o OptionalString) OmitJSONry() bool {
    29  	return !o.IsSet
    30  }
    31  
    32  func (o OptionalString) String() string {
    33  	return o.Value
    34  }