@@ -28,29 +28,29 @@ import (
28
28
const (
29
29
// Sort direction
30
30
31
- sortAscending = "ascending"
32
- sortAsc = "asc"
33
- sortDescending = "descending"
34
- sortDesc = "desc"
31
+ SortAscending = "ascending"
32
+ SortAsc = "asc"
33
+ SortDescending = "descending"
34
+ SortDesc = "desc"
35
35
36
36
// Not all fields can be reached through a json path (Ex: gpu count)
37
37
// so we have special flags for such cases.
38
38
39
- gpuCountField = "gpus"
40
- inferenceAcceleratorsField = "inference-accelerators"
39
+ GPUCountField = "gpus"
40
+ InferenceAcceleratorsField = "inference-accelerators"
41
41
42
42
// shorthand flags
43
43
44
- vcpus = "vcpus"
45
- memory = "memory"
46
- gpuMemoryTotal = "gpu-memory-total"
47
- networkInterfaces = "network-interfaces"
48
- spotPrice = "spot-price"
49
- odPrice = "on-demand-price"
50
- instanceStorage = "instance-storage"
51
- ebsOptimizedBaselineBandwidth = "ebs-optimized-baseline-bandwidth"
52
- ebsOptimizedBaselineThroughput = "ebs-optimized-baseline-throughput"
53
- ebsOptimizedBaselineIOPS = "ebs-optimized-baseline-iops"
44
+ VCPUs = "vcpus"
45
+ Memory = "memory"
46
+ GPUMemoryTotal = "gpu-memory-total"
47
+ NetworkInterfaces = "network-interfaces"
48
+ SpotPrice = "spot-price"
49
+ ODPrice = "on-demand-price"
50
+ InstanceStorage = "instance-storage"
51
+ EBSOptimizedBaselineBandwidth = "ebs-optimized-baseline-bandwidth"
52
+ EBSOptimizedBaselineThroughput = "ebs-optimized-baseline-throughput"
53
+ EBSOptimizedBaselineIOPS = "ebs-optimized-baseline-iops"
54
54
55
55
// JSON field paths for shorthand flags
56
56
@@ -91,16 +91,16 @@ type sorter struct {
91
91
// sortDirection represents the direction to sort in. Valid options: "ascending", "asc", "descending", "desc".
92
92
func Sort (instanceTypes []* instancetypes.Details , sortField string , sortDirection string ) ([]* instancetypes.Details , error ) {
93
93
sortingKeysMap := map [string ]string {
94
- vcpus : vcpuPath ,
95
- memory : memoryPath ,
96
- gpuMemoryTotal : gpuMemoryTotalPath ,
97
- networkInterfaces : networkInterfacesPath ,
98
- spotPrice : spotPricePath ,
99
- odPrice : odPricePath ,
100
- instanceStorage : instanceStoragePath ,
101
- ebsOptimizedBaselineBandwidth : ebsOptimizedBaselineBandwidthPath ,
102
- ebsOptimizedBaselineThroughput : ebsOptimizedBaselineThroughputPath ,
103
- ebsOptimizedBaselineIOPS : ebsOptimizedBaselineIOPSPath ,
94
+ VCPUs : vcpuPath ,
95
+ Memory : memoryPath ,
96
+ GPUMemoryTotal : gpuMemoryTotalPath ,
97
+ NetworkInterfaces : networkInterfacesPath ,
98
+ SpotPrice : spotPricePath ,
99
+ ODPrice : odPricePath ,
100
+ InstanceStorage : instanceStoragePath ,
101
+ EBSOptimizedBaselineBandwidth : ebsOptimizedBaselineBandwidthPath ,
102
+ EBSOptimizedBaselineThroughput : ebsOptimizedBaselineThroughputPath ,
103
+ EBSOptimizedBaselineIOPS : ebsOptimizedBaselineIOPSPath ,
104
104
}
105
105
106
106
// determine if user used a shorthand for sorting flag
@@ -130,12 +130,12 @@ func Sort(instanceTypes []*instancetypes.Details, sortField string, sortDirectio
130
130
func newSorter (instanceTypes []* instancetypes.Details , sortField string , sortDirection string ) (* sorter , error ) {
131
131
var isDescending bool
132
132
switch sortDirection {
133
- case sortDescending , sortDesc :
133
+ case SortDescending , SortDesc :
134
134
isDescending = true
135
- case sortAscending , sortAsc :
135
+ case SortAscending , SortAsc :
136
136
isDescending = false
137
137
default :
138
- return nil , fmt .Errorf ("invalid sort direction: %s (valid options: %s, %s, %s, %s)" , sortDirection , sortAscending , sortAsc , sortDescending , sortDesc )
138
+ return nil , fmt .Errorf ("invalid sort direction: %s (valid options: %s, %s, %s, %s)" , sortDirection , SortAscending , SortAsc , SortDescending , SortDesc )
139
139
}
140
140
141
141
sortField = formatSortField (sortField )
@@ -163,7 +163,7 @@ func newSorter(instanceTypes []*instancetypes.Details, sortField string, sortDir
163
163
// matches one of the special flags.
164
164
func formatSortField (sortField string ) string {
165
165
// check to see if the sorting field matched one of the special exceptions
166
- if sortField == gpuCountField || sortField == inferenceAcceleratorsField {
166
+ if sortField == GPUCountField || sortField == InferenceAcceleratorsField {
167
167
return sortField
168
168
}
169
169
@@ -176,13 +176,13 @@ func newSorterNode(instanceType *instancetypes.Details, sortField string) (*sort
176
176
// some important fields (such as gpu count) can not be accessed directly in the instancetypes.Details
177
177
// struct, so we have special hard-coded flags to handle such cases
178
178
switch sortField {
179
- case gpuCountField :
179
+ case GPUCountField :
180
180
gpuCount := getTotalGpusCount (instanceType )
181
181
return & sorterNode {
182
182
instanceType : instanceType ,
183
183
fieldValue : reflect .ValueOf (gpuCount ),
184
184
}, nil
185
- case inferenceAcceleratorsField :
185
+ case InferenceAcceleratorsField :
186
186
acceleratorsCount := getTotalAcceleratorsCount (instanceType )
187
187
return & sorterNode {
188
188
instanceType : instanceType ,
0 commit comments