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

View File

@ -22,33 +22,33 @@
package goldsmith 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 { type Context interface {
NewFile(path string) File NewFile(srcDir string) File
} }
type File interface { type File interface {
Path() string Path() string
SetPath(path string) SetPath(path string)
Bytes() []byte
SetBytes(bytes []byte)
Property(key, def string) interface{} Property(key, def string) interface{}
SetProperty(key string, value interface{}) SetProperty(key string, value interface{})
Error() error Error() error
SetError(err 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
} }