diff options
Diffstat (limited to 'modules/grils')
-rw-r--r-- | modules/grils/grils.go | 32 |
1 files changed, 2 insertions, 30 deletions
diff --git a/modules/grils/grils.go b/modules/grils/grils.go index 0ba4c61..0fac5df 100644 --- a/modules/grils/grils.go +++ b/modules/grils/grils.go | |||
@@ -4,9 +4,7 @@ import ( | |||
4 | "fmt" | 4 | "fmt" |
5 | "log" | 5 | "log" |
6 | "net/http" | 6 | "net/http" |
7 | "regexp" | ||
8 | "strconv" | 7 | "strconv" |
9 | "strings" | ||
10 | "time" | 8 | "time" |
11 | 9 | ||
12 | "fagott.pw/charakterin" | 10 | "fagott.pw/charakterin" |
@@ -20,20 +18,6 @@ import ( | |||
20 | "github.com/julienschmidt/httprouter" | 18 | "github.com/julienschmidt/httprouter" |
21 | ) | 19 | ) |
22 | 20 | ||
23 | var ( | ||
24 | pgArrayReg = regexp.MustCompile(`(((?P<value>(([^",\\{}\s(NULL)])+|"([^"\\]|\\"|\\\\)*")))(,)?)`) | ||
25 | pgValueIdx int | ||
26 | ) | ||
27 | |||
28 | func findIdx() { | ||
29 | for i, subexp := range pgArrayReg.SubexpNames() { | ||
30 | if subexp == "value" { | ||
31 | pgValueIdx = i | ||
32 | break | ||
33 | } | ||
34 | } | ||
35 | } | ||
36 | |||
37 | type GrilsModule struct { | 21 | type GrilsModule struct { |
38 | g *grilist.Grilist | 22 | g *grilist.Grilist |
39 | c *cache.Cache | 23 | c *cache.Cache |
@@ -44,7 +28,6 @@ func (m *GrilsModule) Name() string { | |||
44 | } | 28 | } |
45 | 29 | ||
46 | func (m *GrilsModule) Init(g *grilist.Grilist) { | 30 | func (m *GrilsModule) Init(g *grilist.Grilist) { |
47 | findIdx() | ||
48 | m.g = g | 31 | m.g = g |
49 | m.g.Router.GET("/gril/:id", m.viewGril) | 32 | m.g.Router.GET("/gril/:id", m.viewGril) |
50 | m.g.Router.GET("/gril/:id/*rest", m.viewGril) | 33 | m.g.Router.GET("/gril/:id/*rest", m.viewGril) |
@@ -77,8 +60,8 @@ func (m *GrilsModule) getGrils(whereClause string, params ...interface{}) ([]*mo | |||
77 | gril.KanjiName = *kanjiName | 60 | gril.KanjiName = *kanjiName |
78 | } | 61 | } |
79 | 62 | ||
80 | gril.Tags = pgArray(tags) | 63 | gril.Tags = util.PGArray(tags) |
81 | gril.OtherNames = pgArray(otherNames) | 64 | gril.OtherNames = util.PGArray(otherNames) |
82 | 65 | ||
83 | m.c.Insert(gril.ID, gril) | 66 | m.c.Insert(gril.ID, gril) |
84 | 67 | ||
@@ -285,17 +268,6 @@ func (m *GrilsModule) viewGril(w http.ResponseWriter, r *http.Request, p httprou | |||
285 | }) | 268 | }) |
286 | } | 269 | } |
287 | 270 | ||
288 | func pgArray(array []byte) []string { | ||
289 | var results []string | ||
290 | matches := pgArrayReg.FindAllStringSubmatch(string(array), -1) | ||
291 | for _, match := range matches { | ||
292 | s := match[pgValueIdx] | ||
293 | s = strings.Trim(s, "\"") | ||
294 | results = append(results, s) | ||
295 | } | ||
296 | return results | ||
297 | } | ||
298 | |||
299 | func New() *GrilsModule { | 271 | func New() *GrilsModule { |
300 | return &GrilsModule{} | 272 | return &GrilsModule{} |
301 | } | 273 | } |