set.go 788 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package pricing
  2. import (
  3. "maps"
  4. "slices"
  5. "github.com/opencost/opencost/core/pkg/unit"
  6. )
  7. type PricingSet struct {
  8. Nodes []*NodePricing `json:"nodes" yaml:"nodes"`
  9. Volumes []*VolumePricing `json:"volumes" yaml:"volumes"`
  10. }
  11. func (ps *PricingSet) IsEmpty() bool {
  12. if ps == nil {
  13. return true
  14. }
  15. return len(ps.Nodes) == 0 && len(ps.Volumes) == 0
  16. }
  17. func (ps *PricingSet) Currencies() []unit.Currency {
  18. if ps == nil {
  19. return []unit.Currency{}
  20. }
  21. currencies := map[unit.Currency]struct{}{}
  22. for _, np := range ps.Nodes {
  23. for _, curr := range np.GetCurrencies() {
  24. currencies[curr] = struct{}{}
  25. }
  26. }
  27. for _, vp := range ps.Volumes {
  28. for _, curr := range vp.GetCurrencies() {
  29. currencies[curr] = struct{}{}
  30. }
  31. }
  32. return slices.Collect(maps.Keys(currencies))
  33. }