in cost-optimization/gke-shift-left-cost/api/cost.go [97:138]
func (c *Cost) ToMarkdown() string {
data := [][]string{}
total := CostRange{Kind: bold("TOTAL")}
for _, mr := range c.MonthlyRanges {
data = append(data,
[]string{mr.Kind,
currency(mr.MinRequested),
currency(mr.HPABuffer),
currency(mr.MaxRequested),
currency(mr.MinLimited),
currency(mr.MaxLimited)})
total.MinRequested = total.MinRequested + mr.MinRequested
total.HPABuffer = total.HPABuffer + mr.HPABuffer
total.MaxRequested = total.MaxRequested + mr.MaxRequested
total.MinLimited = total.MinLimited + mr.MinLimited
total.MaxLimited = total.MaxLimited + mr.MaxLimited
}
data = append(data,
[]string{total.Kind,
bold(currency(total.MinRequested)),
bold(currency(total.HPABuffer)),
bold(currency(total.MaxRequested)),
bold(currency(total.MinLimited)),
bold(currency(total.MaxLimited))})
out := &strings.Builder{}
table := tablewriter.NewWriter(out)
table.SetHeader(
[]string{"Kind",
headers[0] + " (USD)",
headers[1] + " (USD)",
headers[2] + " (USD)",
headers[3] + " (USD)",
headers[4] + " (USD)"})
table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false})
table.SetCenterSeparator("|")
table.SetColumnAlignment([]int{0, 2, 2, 2, 2, 2})
table.AppendBulk(data)
table.Render()
return out.String()
}