goldsmith/interface.go

67 lines
1.5 KiB
Go

package goldsmith
import (
"io"
"time"
)
// Plugin contains the minimum set of methods required on plugins. Plugins can
// also optionally implement Initializer, Processor, and Finalizer interfaces.
type Plugin interface {
Name() string
}
// Initializer is used to optionally initialize a plugin and to specify a
// filter to be used for determining which files will be processed.
type Initializer interface {
Initialize(context *Context) error
}
// Processor allows for optional processing of files passing through a plugin.
type Processor interface {
Process(context *Context, file File) error
}
// Finalizer allows for optional finalization of a plugin after all files
// queued in the chain have passed through it.
type Finalizer interface {
Finalize(context *Context) error
}
// Filter is used to determine which files should continue in the chain.
type Filter interface {
Name() string
Accept(file File) bool
}
type (
FileProp any
FileProps map[string]FileProp
)
// File represents in-memory or on-disk files in a chain.
type File interface {
Path() string
Dir() string
Name() string
Ext() string
Rename(path string) error
Size() int64
ModTime() time.Time
Read(data []byte) (int, error)
WriteTo(writer io.Writer) (int64, error)
Seek(offset int64, whence int) (int64, error)
SetProp(name string, value FileProp)
Prop(name string) (FileProp, bool)
PropOrDef(name string, valueDef FileProp) FileProp
Props() FileProps
CopyProps(file File)
RemoveProp(name string)
GoString() string
Index() int
}