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

     1  package resources
     2  
     3  import (
     4  	"encoding/json"
     5  
     6  	"code.cloudfoundry.org/cli/types"
     7  )
     8  
     9  type Quota struct {
    10  	// GUID is the unique ID of the organization quota.
    11  	GUID string `json:"guid,omitempty"`
    12  	// Name is the name of the organization quota
    13  	Name string `json:"name"`
    14  	// Apps contain the various limits that are associated with applications
    15  	Apps AppLimit `json:"apps"`
    16  	// Services contain the various limits that are associated with services
    17  	Services ServiceLimit `json:"services"`
    18  	// Routes contain the various limits that are associated with routes
    19  	Routes RouteLimit `json:"routes"`
    20  }
    21  
    22  type AppLimit struct {
    23  	TotalMemory       *types.NullInt `json:"total_memory_in_mb,omitempty"`
    24  	InstanceMemory    *types.NullInt `json:"per_process_memory_in_mb,omitempty"`
    25  	TotalAppInstances *types.NullInt `json:"total_instances,omitempty"`
    26  	TotalLogVolume    *types.NullInt `json:"log_rate_limit_in_bytes_per_second,omitempty"`
    27  }
    28  
    29  func (al *AppLimit) UnmarshalJSON(rawJSON []byte) error {
    30  	type Alias AppLimit
    31  
    32  	var aux Alias
    33  	err := json.Unmarshal(rawJSON, &aux)
    34  	if err != nil {
    35  		return err
    36  	}
    37  
    38  	*al = AppLimit(aux)
    39  
    40  	if al.TotalMemory == nil {
    41  		al.TotalMemory = &types.NullInt{
    42  			IsSet: false,
    43  			Value: 0,
    44  		}
    45  	}
    46  
    47  	if al.InstanceMemory == nil {
    48  		al.InstanceMemory = &types.NullInt{
    49  			IsSet: false,
    50  			Value: 0,
    51  		}
    52  	}
    53  
    54  	if al.TotalAppInstances == nil {
    55  		al.TotalAppInstances = &types.NullInt{
    56  			IsSet: false,
    57  			Value: 0,
    58  		}
    59  	}
    60  
    61  	if al.TotalLogVolume == nil {
    62  		al.TotalLogVolume = &types.NullInt{
    63  			IsSet: false,
    64  			Value: 0,
    65  		}
    66  	}
    67  
    68  	return nil
    69  }
    70  
    71  type ServiceLimit struct {
    72  	TotalServiceInstances *types.NullInt `json:"total_service_instances,omitempty"`
    73  	PaidServicePlans      *bool          `json:"paid_services_allowed,omitempty"`
    74  }
    75  
    76  func (sl *ServiceLimit) UnmarshalJSON(rawJSON []byte) error {
    77  	type Alias ServiceLimit
    78  
    79  	var aux Alias
    80  	err := json.Unmarshal(rawJSON, &aux)
    81  	if err != nil {
    82  		return err
    83  	}
    84  
    85  	*sl = ServiceLimit(aux)
    86  
    87  	if sl.TotalServiceInstances == nil {
    88  		sl.TotalServiceInstances = &types.NullInt{
    89  			IsSet: false,
    90  			Value: 0,
    91  		}
    92  	}
    93  
    94  	return nil
    95  }
    96  
    97  type RouteLimit struct {
    98  	TotalRoutes        *types.NullInt `json:"total_routes,omitempty"`
    99  	TotalReservedPorts *types.NullInt `json:"total_reserved_ports,omitempty"`
   100  }
   101  
   102  func (sl *RouteLimit) UnmarshalJSON(rawJSON []byte) error {
   103  	type Alias RouteLimit
   104  
   105  	var aux Alias
   106  	err := json.Unmarshal(rawJSON, &aux)
   107  	if err != nil {
   108  		return err
   109  	}
   110  
   111  	*sl = RouteLimit(aux)
   112  
   113  	if sl.TotalRoutes == nil {
   114  		sl.TotalRoutes = &types.NullInt{
   115  			IsSet: false,
   116  			Value: 0,
   117  		}
   118  	}
   119  
   120  	if sl.TotalReservedPorts == nil {
   121  		sl.TotalReservedPorts = &types.NullInt{
   122  			IsSet: false,
   123  			Value: 0,
   124  		}
   125  	}
   126  
   127  	return nil
   128  }