From 23ba57e6a81d74e6629443570f9dcae8b8327c11 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Tue, 29 Dec 2015 21:08:41 +0900 Subject: [PATCH] Hiding the Meta parameter --- file.go | 18 ++++++++++++------ types.go | 9 +++++---- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/file.go b/file.go index 463f8d7..719fd28 100644 --- a/file.go +++ b/file.go @@ -32,7 +32,7 @@ import ( type file struct { path string - meta map[string]interface{} + Meta map[string]interface{} reader *bytes.Reader asset string @@ -93,13 +93,19 @@ func (f *file) Path() string { return f.path } -func (f *file) Meta() map[string]interface{} { - return f.meta +func (f *file) Value(key string) (interface{}, bool) { + value, ok := f.Meta[key] + return value, ok } -func (f *file) Apply(m map[string]interface{}) { - for key, value := range m { - f.meta[key] = value +func (f *file) SetValue(key string, value interface{}) { + f.Meta[key] = value +} + +func (f *file) CopyValues(src File) { + rf := src.(*file) + for name, value := range rf.Meta { + f.SetValue(name, value) } } diff --git a/types.go b/types.go index 0a3ad02..2451a9a 100644 --- a/types.go +++ b/types.go @@ -46,8 +46,9 @@ func New(srcDir, dstDir string) Goldsmith { type File interface { Path() string - Meta() map[string]interface{} - Apply(m map[string]interface{}) + Value(key string) (interface{}, bool) + SetValue(key string, value interface{}) + CopyValues(src File) Read(p []byte) (int, error) WriteTo(w io.Writer) (int64, error) @@ -57,7 +58,7 @@ type File interface { func NewFileFromData(path string, data []byte) File { return &file{ path: path, - meta: make(map[string]interface{}), + Meta: make(map[string]interface{}), reader: bytes.NewReader(data), } } @@ -65,7 +66,7 @@ func NewFileFromData(path string, data []byte) File { func NewFileFromAsset(path, asset string) File { return &file{ path: path, - meta: make(map[string]interface{}), + Meta: make(map[string]interface{}), asset: asset, } }