Interface improvements

This commit is contained in:
Alex Yatskov 2015-10-31 17:48:53 +09:00
parent 09b861ddfb
commit 954d451cb5
3 changed files with 14 additions and 8 deletions

View File

@ -67,7 +67,7 @@ func (f *file) SetError(err error) {
f.err = err f.err = err
} }
func (f *file) Bytes() []byte { func (f *file) Data() []byte {
if f.buff != nil { if f.buff != nil {
return f.buff.Bytes() return f.buff.Bytes()
} }
@ -91,6 +91,6 @@ func (f *file) Bytes() []byte {
return f.buff.Bytes() return f.buff.Bytes()
} }
func (f *file) SetBytes(data []byte) { func (f *file) SetData(data []byte) {
f.buff = bytes.NewBuffer(data) f.buff = bytes.NewBuffer(data)
} }

View File

@ -23,7 +23,6 @@
package goldsmith package goldsmith
import ( import (
"io/ioutil"
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
@ -41,7 +40,7 @@ type goldsmith struct {
files chan File files chan File
} }
func NewGoldsmith(src string) Goldsmith { func New(src string) Goldsmith {
gs := new(goldsmith) gs := new(goldsmith)
gs.scan(src) gs.scan(src)
return gs return gs
@ -125,7 +124,7 @@ func (gs *goldsmith) Complete(dstDir string) []File {
var files []File var files []File
for file := range s.output { for file := range s.output {
data := file.Bytes() data := file.Data()
if data == nil { if data == nil {
continue continue
} }
@ -137,7 +136,14 @@ func (gs *goldsmith) Complete(dstDir string) []File {
continue continue
} }
if err := ioutil.WriteFile(absPath, data, 0644); err != nil { f, err := os.Create(absPath)
if err != nil {
file.SetError(err)
continue
}
defer f.Close()
if _, err := f.Write(data); err != nil {
file.SetError(err) file.SetError(err)
continue continue
} }

View File

@ -43,8 +43,8 @@ type File interface {
Path() string Path() string
SetPath(path string) SetPath(path string)
Bytes() []byte Data() []byte
SetBytes(bytes []byte) SetData(data []byte)
Property(key, def string) interface{} Property(key, def string) interface{}
SetProperty(key string, value interface{}) SetProperty(key string, value interface{})