Types

The Go library defines types as structs that implement a set of interfaces. Each type provides metadata for manifest generation, handles loading from the inputs/ directory, and knows how to write itself to outputs/.

Interfaces🔗

SpadeType🔗

Provides metadata about a Spade type for manifest generation and output naming:

type SpadeType interface {
    TypeName() string
    DefaultOutputName() string
    ManifestEntry() ManifestInfo
}

FromInput🔗

Constructs a typed value from raw filesystem input data:

type FromInput interface {
    FromSingleFile(path string) error
    FromMultipleFiles(paths []string) error
    FromDirectory(path string) error
}

IntoOutput🔗

Writes a typed value to an output subdirectory:

type IntoOutput interface {
    WriteTo(outputDir string) error
    DefaultOutputName() string
}

Type reference🔗

Single-file types🔗

TypeTypeName()Default output nameFormatProperty
File"file"file--Path string
RasterFile"file"rasterGeoTIFFPath string
VectorFile"file"vectorGeoJSONPath string
TabularFile"file"tabularCSVPath string
JsonFile"json"json--Path string

Each has a constructor: NewFile(path), NewRasterFile(path), etc.

Directory type🔗

TypeTypeName()Default output nameProperty
Directory"directory"directoryPath string

Constructor: NewDirectory(path).

Collection types🔗

TypeTypeName()Default output nameFormatProperty
FileCollection"collection"files--Paths []string
RasterFileCollection"collection"rastersGeoTIFFPaths []string
VectorFileCollection"collection"vectorsGeoJSONPaths []string
TabularFileCollection"collection"tablesCSVPaths []string

Each has a constructor: NewFileCollection(paths), NewRasterFileCollection(paths), etc.

Scalar types (manifest-only)🔗

These types are used only with the ManifestBuilder for declaring parameter types. They are not used at runtime:

TypeTypeName()Manifest type
StringType"string"string
NumberType"number"number
BoolType"boolean"boolean

Using Input and Param🔗

File inputs with Input[T]🔗

The generic Input function retrieves a typed input from Args. T must be a pointer to a struct implementing FromInput:

// Single file
source, err := spade.Input[*spade.RasterFile](args, "source")
// source.Path contains the file path

// Collection
tiles, err := spade.Input[*spade.RasterFileCollection](args, "tiles")
// tiles.Paths contains a slice of file paths

// Directory
dir, err := spade.Input[*spade.Directory](args, "data")
// dir.Path contains the directory path

Scalar parameters with Param[T]🔗

The generic Param function retrieves a scalar parameter from params.yaml:

resolution, err := spade.Param[float64](args, "resolution")
method, err := spade.Param[string](args, "method")
normalize, err := spade.Param[bool](args, "normalize")
count, err := spade.Param[int](args, "count")

The library handles type conversions between YAML's numeric types (int, float64, int64) automatically.

Checking for optional inputs🔗

Use HasInput and HasParam to check before accessing optional arguments:

if args.HasInput("mask") {
    mask, err := spade.Input[*spade.RasterFile](args, "mask")
    // ...
}

if args.HasParam("buffer") {
    buffer, err := spade.Param[float64](args, "buffer")
    // ...
}

Constructing output values🔗

When returning from your handler, construct the appropriate type:

// Single file
result := spade.NewRasterFile("result.tif")
return &result, nil

// Directory
result := spade.NewDirectory("output_dir")
return &result, nil

// Collection
result := spade.NewRasterFileCollection([]string{"tile_001.tif", "tile_002.tif"})
return &result, nil

ManifestInfo🔗

Each type's ManifestEntry() method returns a ManifestInfo struct used by the manifest builder:

type ManifestInfo struct {
    TypeName string // "file", "directory", "collection", "json", "string", etc.
    Format   string // "GeoTIFF", "GeoJSON", "CSV", or empty
    ItemType string // "file" for collections, or empty
}

Error types🔗

The library defines typed errors for input/parameter access:

Error typeWhen it occurs
ErrInputNotFoundInput() called with a name not present in inputs/
ErrParamNotFoundParam() called with a name not present in params.yaml
ErrEmptyInputDirAn input subdirectory exists but contains no files
ErrTypeMismatchInput data cannot be converted to the requested type
ErrSecretNotFoundGetSecret() called with a name not declared in the pipeline's secrets: map, or resolution failed