Skip to content

Commit

Permalink
fix 🐛: various fixes and added currency and consumption plans
Browse files Browse the repository at this point in the history
  • Loading branch information
muandane committed Oct 13, 2023
1 parent 1723083 commit 991f378
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@

# Go workspace file
go.work
.DS_Store
19 changes: 11 additions & 8 deletions src/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ type Response struct {
func main() {
vmType := flag.String("t", "Standard_B4ms", "VM type")
region := flag.String("r", "westus", "Region")
pricingPeriod := flag.String("p", "", "Pricing period (hour or month)")
series := flag.String("s", "", "Azure service (e.g., 'D' for D series vms, Private for Private links)")
flag.StringVar(series, "service", "", "Azure service (e.g., 'D' for D series vms, Private for Private links)")
service := flag.String("s", "", "Azure service (e.g., 'D' for D series vms, Private for Private links)")
pricingType := flag.String("p", "Consumption", "Pricing Type (e.g., 'Consumption' or 'Reservation')")
currency := flag.String("c", "USD", "Price Currency (e.g., 'USD' or 'EUR')")
flag.StringVar(service, "service", "", "Azure service (e.g., 'D' for D series vms, Private for Private links)")
flag.StringVar(vmType, "type", "Standard_B4ms", "VM type")
flag.StringVar(region, "region", "westus", "Region")
flag.StringVar(pricingPeriod, "period", "", "Pricing period (hour or month)")
flag.StringVar(pricingType, "pricing-type", "Consumption", "Pricing Type (e.g., 'Consumption' or 'Reservation')")
flag.StringVar(currency, "currency", "USD", "Price Currency (e.g., 'USD' or 'EUR')")
flag.Parse()

re := lipgloss.NewRenderer(os.Stdout)
Expand All @@ -49,21 +51,22 @@ func main() {
}

var query string
if *series != "" {
query = fmt.Sprintf("armRegionName eq '%s' and contains(armSkuName, '%s') and priceType eq 'Consumption'", *region, *series)
if *service != "" {
query = fmt.Sprintf("armRegionName eq '%s' and contains(serviceName, '%s')", *region, *service)
} else if *vmType != "" {
query = fmt.Sprintf("armRegionName eq '%s' and armSkuName eq '%s' and priceType eq 'Consumption'", *region, *vmType)
query = fmt.Sprintf("armRegionName eq '%s' and contains(armSkuName, '%s') and priceType eq '%s'", *region, *vmType, *pricingType)
} else {
fmt.Println("Please provide either a series or type flag.")
return
}

tableData := [][]string{{"SKU", "Retail Price", "Unit of Measure", "Region", "Meter", "Product Name"}}
apiURL := "https://prices.azure.com/api/retail/prices?"
currencyType := fmt.Sprintf("currencyCode='%s'", *currency)

for {
var resp Response
err := getJSON(apiURL+"&$filter="+url.QueryEscape(query), &resp)
err := getJSON(apiURL+currencyType+"&$filter="+url.QueryEscape(query), &resp)
if err != nil {
fmt.Println("Error:", err)
return
Expand Down

0 comments on commit 991f378

Please sign in to comment.