aboutsummaryrefslogtreecommitdiff
path: root/modules/grils
diff options
context:
space:
mode:
authorrtz12 <koenig@fagott.pw>2016-11-15 17:29:02 (UTC)
committerrtz12 <koenig@fagott.pw>2016-11-15 17:29:02 (UTC)
commit0ad174d7329e02b3f644614de0758789bb3677d4 (patch)
treee49a659c0b89bdec07cde778850b7fe002ac27ea /modules/grils
parente02ad854383265db216ed92b10c4f12408999d6a (diff)
Verrückter Anilist Import
Bestes Feature 2k16. Hashtag Make Grilist Great Again.
Diffstat (limited to 'modules/grils')
-rw-r--r--modules/grils/grils.go32
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
23var (
24 pgArrayReg = regexp.MustCompile(`(((?P<value>(([^",\\{}\s(NULL)])+|"([^"\\]|\\"|\\\\)*")))(,)?)`)
25 pgValueIdx int
26)
27
28func findIdx() {
29 for i, subexp := range pgArrayReg.SubexpNames() {
30 if subexp == "value" {
31 pgValueIdx = i
32 break
33 }
34 }
35}
36
37type GrilsModule struct { 21type 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
46func (m *GrilsModule) Init(g *grilist.Grilist) { 30func (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
288func 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
299func New() *GrilsModule { 271func New() *GrilsModule {
300 return &GrilsModule{} 272 return &GrilsModule{}
301} 273}