summaryrefslogtreecommitdiff
path: root/imagestore/namepathmapper.go
diff options
context:
space:
mode:
authorhorus_arch2015-04-19 22:09:52 +0200
committerhorus_arch2015-04-19 22:09:52 +0200
commit01e9a34952bd6ddd383680b0ca2312e476ad07a6 (patch)
tree00902575e5c271cc5d35ea65aa8795b8caeb97bc /imagestore/namepathmapper.go
downloadmandible-01e9a34952bd6ddd383680b0ca2312e476ad07a6.tar.gz
Initial commit.
Diffstat (limited to 'imagestore/namepathmapper.go')
-rw-r--r--imagestore/namepathmapper.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/imagestore/namepathmapper.go b/imagestore/namepathmapper.go
new file mode 100644
index 0000000..919007b
--- /dev/null
+++ b/imagestore/namepathmapper.go
@@ -0,0 +1,34 @@
+package imagestore
+
+import (
+ "regexp"
+ "strings"
+)
+
+type NamePathMapper struct {
+ regex *regexp.Regexp
+ replace string
+}
+
+func NewNamePathMapper(expr string, mapping string) *NamePathMapper {
+ var r *regexp.Regexp
+ if len(expr) > 0 {
+ r = regexp.MustCompile(expr)
+ }
+
+ return &NamePathMapper{
+ r,
+ mapping,
+ }
+}
+
+func (this *NamePathMapper) mapToPath(obj *StoreObject) string {
+ repl := strings.Replace(this.replace, "${ImageName}", obj.Name, -1)
+ repl = strings.Replace(repl, "${ImageSize}", obj.Type, -1)
+
+ if this.regex != nil {
+ return this.regex.ReplaceAllString(obj.Name, repl)
+ }
+
+ return repl
+}