This commit is contained in:
Alex Yatskov 2015-10-29 19:08:58 +09:00
parent ceca011023
commit 3883d1dedc
2 changed files with 18 additions and 10 deletions

15
core.go
View File

@ -35,15 +35,14 @@ type stage struct {
} }
type goldsmith struct { type goldsmith struct {
Context srcPath, dstPath string
stages []stage stages []stage
files chan File files chan File
wg sync.WaitGroup wg sync.WaitGroup
} }
func NewGoldsmith(srcPath, dstPath string) (Applier, error) { func NewGoldsmith(srcPath, dstPath string) (Applier, error) {
gs := &goldsmith{Context: Context{srcPath, dstPath}} gs := &goldsmith{srcPath: srcPath, dstPath: dstPath}
if err := gs.scan(); err != nil { if err := gs.scan(); err != nil {
return nil, err return nil, err
} }
@ -83,6 +82,14 @@ func (gs *goldsmith) stage() stage {
return s return s
} }
func (gs *goldsmith) AbsSrcPath(path string) string {
return filepath.Join(gs.srcPath, path)
}
func (gs *goldsmith) AbsDstPath(path string) string {
return filepath.Join(gs.dstPath, path)
}
func (gs *goldsmith) Apply(p Processor) Applier { func (gs *goldsmith) Apply(p Processor) Applier {
return gs.ApplyTo(p, "*") return gs.ApplyTo(p, "*")
} }
@ -92,7 +99,7 @@ func (gs *goldsmith) ApplyTo(p Processor, pattern string) Applier {
gs.wg.Add(1) gs.wg.Add(1)
go func() { go func() {
p.ProcessFiles(s.input, s.output) p.Process(gs, s.input, s.output)
gs.wg.Done() gs.wg.Done()
}() }()

View File

@ -22,8 +22,9 @@
package goldsmith package goldsmith
type Context struct { type Context interface {
srcPath, dstPath string AbsSrcPath(path string) string
AbsDstPath(path string) string
} }
type File struct { type File struct {
@ -32,7 +33,7 @@ type File struct {
} }
type Processor interface { type Processor interface {
ProcessFiles(input chan File, output chan File) error Process(ctx Context, input chan File, output chan File) error
} }
type Applier interface { type Applier interface {