refactoring: implement review feedback

This commit is contained in:
David Christofas
2020-03-11 14:18:25 +01:00
parent 261429ef72
commit 985c11896f
4 changed files with 27 additions and 41 deletions
+5 -27
View File
@@ -1,33 +1,11 @@
package imgsource
import "image"
import (
"context"
"image"
)
// Source defines the interface for image sources
type Source interface {
Get(path string, ctx SourceContext) (image.Image, error)
}
// NewContext creates a new SourceContext instance
func NewContext() SourceContext {
return SourceContext{
m: make(map[string]interface{}),
}
}
// SourceContext is used to pass source specific parameters
type SourceContext struct {
m map[string]interface{}
}
// GetString tries to cast the value to a string
func (s SourceContext) GetString(key string) string {
if s, ok := s.m[key].(string); ok {
return s
}
return ""
}
// Set sets a value
func (s SourceContext) Set(key string, val interface{}) {
s.m[key] = val
Get(ctx context.Context, path string) (image.Image, error)
}