Skip to content

Commit

Permalink
Update: add types to struct
Browse files Browse the repository at this point in the history
  • Loading branch information
till committed Mar 10, 2024
1 parent adb9668 commit 9fc1908
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
14 changes: 7 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,30 @@ func main() {
if err != nil {
panic(err)
}
fmt.Printf("Got tenant id: %s\n", tenantId)
fmt.Printf("Got tenant id: %s\n\n", tenantId)

usageData, err := aci.GetUsage(tenantId)
if err != nil {
panic(err)
}

for _, items := range usageData.Items {
//fmt.Printf("Got tenant ID: %s\n", items.Tenant)
for _, usages := range items.Usages {
if usages["name"] != "hci_s3_storage" {
if usages.Name != "hci_s3_storage" {
continue
}

app, err := aci.GetApplication(usages["application_id"].(string))
app, err := aci.GetApplication(usages.ApplicationID)
if err != nil {
panic(err)
}
fmt.Printf("%s (Type: %s)\n\n%s -- %.2f GB\n",

fmt.Printf("%s (Type: %s)\n%s -- %.2f GB\n\n",
app.Name,
app.Type,
usages["name"],
usages.Name,
// bitshift -> byte to gb
(usages["absolute_value"].(float64) / (1 << 30)))
(usages.AbsoluteValue / (1 << 30)))
}
}
}
30 changes: 27 additions & 3 deletions pkg/acronis/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,37 @@ type ApplicationResponse struct {
Type string `json:"type"`
}

type UsageItems struct {
Tenant string `json:"tenant"`
Usages []UsageItem `json:"usages"`
}

type UsageItem struct {
Tenant string `json:"tenant"`
Usages []map[string]interface{} `json:"usages"`
AbsoluteValue float64 `json:"absolute_value"`
ApplicationID string `json:"application_id"`
Edition interface{} `json:"edition"`
InfraID string `json:"infra_id"`
MeasurementUnit string `json:"measurement_unit"`
Name string `json:"name"`
RangeStart string `json:"range_start"`
TenantID float64 `json:"tenant_id"`
ItemType string `json:"type"`
UsageName string `json:"usage_name"`
Value float64 `json:"value"`

// not relevant but there
OfferingItem struct {
Status int `json:"status"`
Quota struct {
Value interface{} `json:"value"`
Overage interface{} `json:"overage"`
Version int `json:"version"`
} `json:"quota"`
} `json:"offering_item,omitempty"`
}

type UsageResponse struct {
Items []UsageItem `json:"items"`
Items []UsageItems `json:"items"`
}

type clientResponse struct {
Expand Down

0 comments on commit 9fc1908

Please sign in to comment.