Interface improvements

This commit is contained in:
Alex Yatskov 2015-10-31 16:06:38 +09:00
parent 09a445fdd9
commit 4ff5959034
2 changed files with 27 additions and 27 deletions

View File

@ -86,14 +86,14 @@ func (gs *goldsmith) NewFile(relPath string) File {
return &file{relPath: relPath}
}
func (gs *goldsmith) applySingle(proc ProcessorSingle) {
func (gs *goldsmith) taskSingle(ts TaskerSingle) {
s := gs.makeStage()
var wg sync.WaitGroup
for file := range s.input {
wg.Add(1)
go func(f File) {
s.output <- proc.ProcessSingle(gs, f)
s.output <- ts.TaskSingle(gs, f)
wg.Done()
}(file)
}
@ -104,17 +104,17 @@ func (gs *goldsmith) applySingle(proc ProcessorSingle) {
}()
}
func (gs *goldsmith) applyMultiple(proc ProcessorMultiple) {
func (gs *goldsmith) taskMultiple(tm TaskerMultiple) {
s := gs.makeStage()
proc.ProcessMultiple(gs, s.input, s.output)
tm.TaskMultiple(gs, s.input, s.output)
}
func (gs *goldsmith) Apply(proc interface{}) Goldsmith {
switch p := proc.(type) {
case ProcessorSingle:
gs.applySingle(p)
case ProcessorMultiple:
gs.applyMultiple(p)
func (gs *goldsmith) Task(task interface{}) Goldsmith {
switch t := task.(type) {
case TaskerSingle:
gs.taskSingle(t)
case TaskerMultiple:
gs.taskMultiple(t)
}
return gs

View File

@ -22,33 +22,33 @@
package goldsmith
type Goldsmith interface {
Task(task interface{}) Goldsmith
Complete(dstDir string) []File
}
type TaskerSingle interface {
TaskSingle(ctx Context, file File) File
}
type TaskerMultiple interface {
TaskMultiple(ctx Context, input, output chan File)
}
type Context interface {
NewFile(path string) File
NewFile(srcDir string) File
}
type File interface {
Path() string
SetPath(path string)
Bytes() []byte
SetBytes(bytes []byte)
Property(key, def string) interface{}
SetProperty(key string, value interface{})
Error() error
SetError(err error)
Bytes() []byte
SetBytes(bytes []byte)
}
type ProcessorMultiple interface {
ProcessMultiple(ctx Context, input, output chan File)
}
type ProcessorSingle interface {
ProcessSingle(ctx Context, file File) File
}
type Goldsmith interface {
Apply(proc interface{}) Goldsmith
Complete(path string) []File
}