name.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package pipelines
  2. import (
  3. "github.com/opencost/opencost/core/pkg/opencost"
  4. "github.com/opencost/opencost/core/pkg/util/typeutil"
  5. )
  6. const (
  7. AllocationPipelineName string = "allocations"
  8. AssetsPipelineName string = "assets"
  9. CloudCostsPipelineName string = "cloudcosts"
  10. NetworkInsightPipelineName string = "networkinsights"
  11. CustomCostsPipelineName string = "customcosts"
  12. )
  13. var nameByType map[string]string
  14. // initializes the package, creates type -> pipeline mapping
  15. func init() {
  16. allocSetKey := typeutil.TypeOf[opencost.AllocationSet]()
  17. allocKey := typeutil.TypeOf[opencost.Allocation]()
  18. assetSetKey := typeutil.TypeOf[opencost.AssetSet]()
  19. assetKey := typeutil.TypeOf[opencost.Asset]()
  20. cloudCostsSetKey := typeutil.TypeOf[opencost.CloudCostSet]()
  21. cloudCostKey := typeutil.TypeOf[opencost.CloudCost]()
  22. networkInsightSetKey := typeutil.TypeOf[opencost.NetworkInsightSet]()
  23. networkInsightKey := typeutil.TypeOf[opencost.NetworkInsight]()
  24. nameByType = map[string]string{
  25. allocSetKey: AllocationPipelineName,
  26. allocKey: AllocationPipelineName,
  27. assetSetKey: AssetsPipelineName,
  28. assetKey: AssetsPipelineName,
  29. cloudCostsSetKey: CloudCostsPipelineName,
  30. cloudCostKey: CloudCostsPipelineName,
  31. networkInsightSetKey: NetworkInsightPipelineName,
  32. networkInsightKey: NetworkInsightPipelineName,
  33. }
  34. }
  35. func NameFor[T any]() string {
  36. return nameByType[typeutil.TypeOf[T]()]
  37. }