From 946e77e9eee58404e5cfe181ade9f9732271e927 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Thu, 29 Oct 2015 22:07:27 +0900 Subject: [PATCH] WIP --- cmd/main.go | 4 +--- core.go | 39 +++++++++++++++++++++++++++++++++------ goldsmith.go | 15 +++++++++++---- 3 files changed, 45 insertions(+), 13 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index 1748e60..6c599e9 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -22,9 +22,7 @@ package main -import "github.com/FooSoft/goldsmith" +import _ "github.com/FooSoft/goldsmith" func main() { - gs := goldsmith.NewGoldsmith("", "") - gs.Use(nil) } diff --git a/core.go b/core.go index 1a0fd77..a3f3190 100644 --- a/core.go +++ b/core.go @@ -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 { diff --git a/goldsmith.go b/goldsmith.go index 951ad5d..44ab091 100644 --- a/goldsmith.go +++ b/goldsmith.go @@ -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 {