Setup SourceUnit interface (#1393)

* Test: Asymmetrical unmarshal API

* Test: Symmetric marshal API

* Revert "Test: Symmetric marshal API"

This reverts commit f51c64a797.

* Cleanup test example and add SourceUnitUnmarshaller interface

* Add CommonSourceUnit implementation

* Update comments

* Remove UnmarshalJSON
This commit is contained in:
Miccah 2023-06-16 10:38:28 -05:00 committed by GitHub
parent 401688d0a8
commit e12f0f84a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 0 deletions

View file

@ -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
}

View file

@ -44,6 +44,19 @@ type Source interface {
GetProgress() *Progress 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. // GCSConfig defines the optional configuration for a GCS source.
type GCSConfig struct { type GCSConfig struct {
// CloudCred determines whether to use cloud credentials. // CloudCred determines whether to use cloud credentials.