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
}
func (f *file) Bytes() []byte {
func (f *file) Data() []byte {
if f.buff != nil {
return f.buff.Bytes()
}
@ -91,6 +91,6 @@ func (f *file) Bytes() []byte {
return f.buff.Bytes()
}
func (f *file) SetBytes(data []byte) {
func (f *file) SetData(data []byte) {
f.buff = bytes.NewBuffer(data)
}

View File

@ -23,7 +23,6 @@
package goldsmith
import (
"io/ioutil"
"os"
"path"
"path/filepath"
@ -41,7 +40,7 @@ type goldsmith struct {
files chan File
}
func NewGoldsmith(src string) Goldsmith {
func New(src string) Goldsmith {
gs := new(goldsmith)
gs.scan(src)
return gs
@ -125,7 +124,7 @@ func (gs *goldsmith) Complete(dstDir string) []File {
var files []File
for file := range s.output {
data := file.Bytes()
data := file.Data()
if data == nil {
continue
}
@ -137,7 +136,14 @@ func (gs *goldsmith) Complete(dstDir string) []File {
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)
continue
}

View File

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