service.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package pricing
  2. import (
  3. "fmt"
  4. "time"
  5. "github.com/opencost/opencost/core/pkg/model/shared"
  6. )
  7. type ServicePricing struct {
  8. Properties ServicePricingProperties `json:"properties" yaml:"properties"`
  9. Prices Prices `json:"prices" yaml:"prices"`
  10. }
  11. func (sp *ServicePricing) String() string {
  12. return sp.Properties.String() + "|" + sp.Prices.canonical()
  13. }
  14. type ServicePricingProperties struct {
  15. Provider shared.Provider `json:"provider,omitempty" yaml:"provider,omitempty"`
  16. Region string `json:"region,omitempty" yaml:"region,omitempty"`
  17. Start *time.Time `json:"start,omitempty" yaml:"start,omitempty"`
  18. End *time.Time `json:"end,omitempty" yaml:"end,omitempty"`
  19. }
  20. func (sp *ServicePricingProperties) String() string {
  21. return fmt.Sprintf("%s:%s:%s",
  22. sp.Provider,
  23. sp.Region,
  24. sp.timeKey(),
  25. )
  26. }
  27. func (sp *ServicePricingProperties) timeKey() string {
  28. s := "nil"
  29. e := "nil"
  30. if sp.Start != nil {
  31. s = sp.Start.UTC().Format(time.RFC3339Nano)
  32. }
  33. if sp.End != nil {
  34. e = sp.End.UTC().Format(time.RFC3339Nano)
  35. }
  36. return fmt.Sprintf("%s:%s", s, e)
  37. }