Skip to content

Commit

Permalink
Setup SourceUnit interface (#1393)
Browse files Browse the repository at this point in the history
* Test: Asymmetrical unmarshal API

* Test: Symmetric marshal API

* Revert "Test: Symmetric marshal API"

This reverts commit f51c64a.

* Cleanup test example and add SourceUnitUnmarshaller interface

* Add CommonSourceUnit implementation

* Update comments

* Remove UnmarshalJSON
  • Loading branch information
mcastorina committed Jun 16, 2023
1 parent 401688d commit e12f0f8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/sources/source_unit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package sources

// CommonSourceUnit is a common implementation of SourceUnit that Sources can
// use instead of implementing their own types.
type CommonSourceUnit struct {
ID string `json:"source_unit_id"`
}

// Implement the SourceUnit interface.
func (c CommonSourceUnit) SourceUnitID() string {
return c.ID
}
13 changes: 13 additions & 0 deletions pkg/sources/sources.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ type Source interface {
GetProgress() *Progress
}

// SourceUnitUnmarshaller defines an optional interface a Source can implement
// to support units coming from an external source.
type SourceUnitUnmarshaller interface {
UnmarshalSourceUnit(data []byte) (SourceUnit, error)
}

// SourceUnit is an object that represents a Source's unit of work. This is
// used as the output of enumeration, progress reporting, and job distribution.
type SourceUnit interface {
// SourceUnitID uniquely identifies a source unit.
SourceUnitID() string
}

// GCSConfig defines the optional configuration for a GCS source.
type GCSConfig struct {
// CloudCred determines whether to use cloud credentials.
Expand Down

0 comments on commit e12f0f8

Please sign in to comment.