diff options
Diffstat (limited to 'modules/grils/gril.go')
-rw-r--r-- | modules/grils/gril.go | 23 |
1 files changed, 23 insertions, 0 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 | } | ||