This commit is contained in:
Alex Yatskov 2015-10-29 22:07:27 +09:00
parent be7d133c12
commit 946e77e9ee
3 changed files with 45 additions and 13 deletions

View File

@ -22,9 +22,7 @@
package main
import "github.com/FooSoft/goldsmith"
import _ "github.com/FooSoft/goldsmith"
func main() {
gs := goldsmith.NewGoldsmith("", "")
gs.Use(nil)
}

39
core.go
View File

@ -23,6 +23,7 @@
package goldsmith
import (
"bytes"
"path/filepath"
"sync"
@ -30,17 +31,43 @@ import (
)
type stage struct {
input chan File
output chan File
input chan file
output chan file
}
type file struct {
path string
meta map[string]interface{}
}
type goldsmith struct {
srcPath, dstPath string
stages []stage
files chan File
files chan file
wg sync.WaitGroup
}
func (f *file) Path() string {
return f.path
}
func (f *file) SetPath(path string) {
f.path = path
}
func (f *file) Meta(key string) (interface{}, bool) {
value, ok := f.meta[key]
return value, ok
}
func (f *file) SetMeta(key string, value interface{}) {
f.meta[key] = value
}
func (f *file) Data() (*bytes.Buffer, error) {
return nil, nil
}
func NewGoldsmith(srcPath, dstPath string) (Applier, error) {
gs := &goldsmith{srcPath: srcPath, dstPath: dstPath}
if err := gs.scan(); err != nil {
@ -56,7 +83,7 @@ func (gs *goldsmith) scan() error {
return err
}
gs.files = make(chan File, len(matches))
gs.files = make(chan file, len(matches))
for _, match := range matches {
path, err := filepath.Rel(gs.srcPath, match)
@ -64,14 +91,14 @@ func (gs *goldsmith) scan() error {
return err
}
gs.files <- File{path, make(map[string]interface{})}
gs.files <- file{path, make(map[string]interface{})}
}
return nil
}
func (gs *goldsmith) stage() stage {
s := stage{output: make(chan File)}
s := stage{output: make(chan file)}
if len(gs.stages) == 0 {
s.input = gs.files
} else {

View File

@ -22,18 +22,25 @@
package goldsmith
import "bytes"
type Context interface {
AbsSrcPath(path string) string
AbsDstPath(path string) string
}
type File struct {
Path string
Meta map[string]interface{}
type File interface {
Path() string
SetPath(path string)
Meta(key string) (interface{}, bool)
SetMeta(key string, value interface{})
Data() (*bytes.Buffer, error)
}
type Processor interface {
Process(ctx Context, input chan File, output chan File) error
Process(ctx Context, input chan file, output chan file) error
}
type Applier interface {