Updating interface

This commit is contained in:
Alex Yatskov 2015-10-31 15:57:03 +09:00
parent b343397ec5
commit 09a445fdd9
3 changed files with 11 additions and 8 deletions

10
file.go
View File

@ -63,9 +63,9 @@ func (f *file) SetError(err error) {
f.err = err f.err = err
} }
func (f *file) Data() *bytes.Buffer { func (f *file) Bytes() []byte {
if f.buff != nil { if f.buff != nil {
return f.buff return f.buff.Bytes()
} }
var buff bytes.Buffer var buff bytes.Buffer
@ -84,5 +84,9 @@ func (f *file) Data() *bytes.Buffer {
} }
f.buff = &buff f.buff = &buff
return f.buff return f.buff.Bytes()
}
func (f *file) SetBytes(data []byte) {
f.buff = bytes.NewBuffer(data)
} }

View File

@ -125,7 +125,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.Data() data := file.Bytes()
if data == nil { if data == nil {
continue continue
} }
@ -137,7 +137,7 @@ func (gs *goldsmith) Complete(dstDir string) []File {
continue continue
} }
if err := ioutil.WriteFile(absPath, data.Bytes(), 0644); err != nil { if err := ioutil.WriteFile(absPath, data, 0644); err != nil {
file.SetError(err) file.SetError(err)
continue continue
} }

View File

@ -22,8 +22,6 @@
package goldsmith package goldsmith
import "bytes"
type Context interface { type Context interface {
NewFile(path string) File NewFile(path string) File
} }
@ -38,7 +36,8 @@ type File interface {
Error() error Error() error
SetError(err error) SetError(err error)
Data() *bytes.Buffer Bytes() []byte
SetBytes(bytes []byte)
} }
type ProcessorMultiple interface { type ProcessorMultiple interface {