diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/grils/gril.go | 23 | ||||
-rw-r--r-- | modules/grils/grils.go | 23 | ||||
-rw-r--r-- | modules/lists/lists.go | 5 |
3 files changed, 25 insertions, 26 deletions
diff --git a/modules/grils/gril.go b/modules/grils/gril.go index edf25a9..a450647 100644 --- a/modules/grils/gril.go +++ b/modules/grils/gril.go | |||
@@ -2,7 +2,9 @@ package grils | |||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "database/sql" | 4 | "database/sql" |
5 | "fmt" | ||
5 | "github.com/lib/pq" | 6 | "github.com/lib/pq" |
7 | "os" | ||
6 | "time" | 8 | "time" |
7 | ) | 9 | ) |
8 | 10 | ||
@@ -25,3 +27,24 @@ type Gril struct { | |||
25 | UpdatedAt time.Time | 27 | UpdatedAt time.Time |
26 | Lists []int | 28 | Lists []int |
27 | } | 29 | } |
30 | |||
31 | func (g *Gril) ImagePath() string { | ||
32 | exts := []string{"png", "jpg", "gif", "jpeg"} | ||
33 | var imagePath string | ||
34 | for _, ext := range exts { | ||
35 | path := fmt.Sprintf("assets/img/gril/%d/0.%s", g.ID, ext) | ||
36 | if _, err := os.Stat(path); err == nil { | ||
37 | return path | ||
38 | } | ||
39 | } | ||
40 | |||
41 | if len(imagePath) == 0 { | ||
42 | for _, ext := range exts { | ||
43 | path := fmt.Sprintf("assets/img/gril/%d/1.%s", g.ID, ext) | ||
44 | if _, err := os.Stat(path); err == nil { | ||
45 | return path | ||
46 | } | ||
47 | } | ||
48 | } | ||
49 | return "" | ||
50 | } | ||
diff --git a/modules/grils/grils.go b/modules/grils/grils.go index 9bfd6e6..a1c84c7 100644 --- a/modules/grils/grils.go +++ b/modules/grils/grils.go | |||
@@ -8,7 +8,6 @@ import ( | |||
8 | "github.com/julienschmidt/httprouter" | 8 | "github.com/julienschmidt/httprouter" |
9 | "log" | 9 | "log" |
10 | "net/http" | 10 | "net/http" |
11 | "os" | ||
12 | "regexp" | 11 | "regexp" |
13 | "strconv" | 12 | "strconv" |
14 | "strings" | 13 | "strings" |
@@ -174,28 +173,6 @@ func (m *GrilsModule) viewGril(w http.ResponseWriter, r *http.Request, p httprou | |||
174 | data["user"] = user | 173 | data["user"] = user |
175 | data["gril"] = gril | 174 | data["gril"] = gril |
176 | 175 | ||
177 | // get the file ending | ||
178 | exts := []string{"png", "jpg", "gif", "jpeg"} | ||
179 | var imagePath string | ||
180 | for _, ext := range exts { | ||
181 | path := fmt.Sprintf("assets/img/gril/%d/0.%s", gril.ID, ext) | ||
182 | if _, err := os.Stat(path); err == nil { | ||
183 | imagePath = path | ||
184 | break | ||
185 | } | ||
186 | } | ||
187 | |||
188 | if len(imagePath) == 0 { | ||
189 | for _, ext := range exts { | ||
190 | path := fmt.Sprintf("assets/img/gril/%d/1.%s", gril.ID, ext) | ||
191 | if _, err := os.Stat(path); err == nil { | ||
192 | imagePath = path | ||
193 | break | ||
194 | } | ||
195 | } | ||
196 | } | ||
197 | data["imagePath"] = "/" + imagePath | ||
198 | |||
199 | m.g.Renderer.RenderPage("gril", w, data) | 176 | m.g.Renderer.RenderPage("gril", w, data) |
200 | } | 177 | } |
201 | 178 | ||
diff --git a/modules/lists/lists.go b/modules/lists/lists.go index 94d4030..4c4288f 100644 --- a/modules/lists/lists.go +++ b/modules/lists/lists.go | |||
@@ -34,9 +34,8 @@ type List struct { | |||
34 | 34 | ||
35 | // ListGril ist ein geranktes Gril | 35 | // ListGril ist ein geranktes Gril |
36 | type ListGril struct { | 36 | type ListGril struct { |
37 | Gril *grils.Gril | 37 | Gril *grils.Gril |
38 | Order int | 38 | Order int |
39 | ImagePath string | ||
40 | } | 39 | } |
41 | 40 | ||
42 | // Name gibt den Namen des Moduls zurück | 41 | // Name gibt den Namen des Moduls zurück |