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 package main
import "github.com/FooSoft/goldsmith" import _ "github.com/FooSoft/goldsmith"
func main() { func main() {
gs := goldsmith.NewGoldsmith("", "")
gs.Use(nil)
} }

39
core.go
View File

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

View File

@ -22,18 +22,25 @@
package goldsmith package goldsmith
import "bytes"
type Context interface { type Context interface {
AbsSrcPath(path string) string AbsSrcPath(path string) string
AbsDstPath(path string) string AbsDstPath(path string) string
} }
type File struct { type File interface {
Path string Path() string
Meta map[string]interface{} SetPath(path string)
Meta(key string) (interface{}, bool)
SetMeta(key string, value interface{})
Data() (*bytes.Buffer, error)
} }
type Processor interface { 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 { type Applier interface {