network.go 1017 B

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