Hiding the Meta parameter

This commit is contained in:
Alex Yatskov 2015-12-29 21:08:41 +09:00
parent 24db16ccf7
commit 23ba57e6a8
2 changed files with 17 additions and 10 deletions

18
file.go
View File

@ -32,7 +32,7 @@ import (
type file struct { type file struct {
path string path string
meta map[string]interface{} Meta map[string]interface{}
reader *bytes.Reader reader *bytes.Reader
asset string asset string
@ -93,13 +93,19 @@ func (f *file) Path() string {
return f.path return f.path
} }
func (f *file) Meta() map[string]interface{} { func (f *file) Value(key string) (interface{}, bool) {
return f.meta value, ok := f.Meta[key]
return value, ok
} }
func (f *file) Apply(m map[string]interface{}) { func (f *file) SetValue(key string, value interface{}) {
for key, value := range m { f.Meta[key] = value
f.meta[key] = value }
func (f *file) CopyValues(src File) {
rf := src.(*file)
for name, value := range rf.Meta {
f.SetValue(name, value)
} }
} }

View File

@ -46,8 +46,9 @@ func New(srcDir, dstDir string) Goldsmith {
type File interface { type File interface {
Path() string Path() string
Meta() map[string]interface{} Value(key string) (interface{}, bool)
Apply(m map[string]interface{}) SetValue(key string, value interface{})
CopyValues(src File)
Read(p []byte) (int, error) Read(p []byte) (int, error)
WriteTo(w io.Writer) (int64, error) WriteTo(w io.Writer) (int64, error)
@ -57,7 +58,7 @@ type File interface {
func NewFileFromData(path string, data []byte) File { func NewFileFromData(path string, data []byte) File {
return &file{ return &file{
path: path, path: path,
meta: make(map[string]interface{}), Meta: make(map[string]interface{}),
reader: bytes.NewReader(data), reader: bytes.NewReader(data),
} }
} }
@ -65,7 +66,7 @@ func NewFileFromData(path string, data []byte) File {
func NewFileFromAsset(path, asset string) File { func NewFileFromAsset(path, asset string) File {
return &file{ return &file{
path: path, path: path,
meta: make(map[string]interface{}), Meta: make(map[string]interface{}),
asset: asset, asset: asset,
} }
} }