source.go 1.0 KB

123456789101112131415161718192021222324252627
  1. package exporter
  2. import "time"
  3. // ExportSource[T] provides a factory style contract for creating new `T` instances for exporting.
  4. type ExportSource[T any] interface {
  5. Make(timestamp time.Time) *T
  6. // Name returns the name of the ExportSource.
  7. Name() string
  8. }
  9. // ComputeSource[T] provides an interface for a compute data source.
  10. type ComputeSource[T any] interface {
  11. // CanCompute should return true iff the ComputeSource can effectively act as
  12. // a source of T data for the given time range. For example, a ComputeSource
  13. // with two-day coverage cannot fulfill a range from three days ago, and should
  14. // not be left to return an error in Compute. Instead, it should report that is
  15. // cannot compute and allow another Source to handle the computation.
  16. CanCompute(start, end time.Time) bool
  17. // Compute should compute a single T for the given time range, optionally using the given resolution.
  18. Compute(start, end time.Time, resolution time.Duration) (*T, error)
  19. // Name returns the name of the ComputeSource
  20. Name() string
  21. }