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
}
func (f *file) Data() *bytes.Buffer {
func (f *file) Bytes() []byte {
if f.buff != nil {
return f.buff
return f.buff.Bytes()
}
var buff bytes.Buffer
@ -84,5 +84,9 @@ func (f *file) Data() *bytes.Buffer {
}
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
for file := range s.output {
data := file.Data()
data := file.Bytes()
if data == nil {
continue
}
@ -137,7 +137,7 @@ func (gs *goldsmith) Complete(dstDir string) []File {
continue
}
if err := ioutil.WriteFile(absPath, data.Bytes(), 0644); err != nil {
if err := ioutil.WriteFile(absPath, data, 0644); err != nil {
file.SetError(err)
continue
}

View File

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