Skip to content

Commit 3c881e3

Browse files
authored
add support for multiple languages (ccbrown#19)
1 parent ebdeff6 commit 3c881e3

16 files changed

+462
-60
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
*
2+
!Gopkg.*
23
!*.go
34
!server/*

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
*.db
22
gggtracker
3+
/vendor

Dockerfile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
FROM golang:alpine
1+
FROM golang:1.10-alpine
22

33
WORKDIR /go/src/github.com/ccbrown/gggtracker
4-
ADD . .
54

6-
RUN apk add --no-cache git && go get -t ./...
5+
RUN apk add --no-cache git
6+
RUN wget -O - https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
7+
8+
ADD . .
9+
RUN dep ensure
710
RUN go vet . && go test -v ./...
811
RUN go build .
912

Gopkg.lock

Lines changed: 224 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Gopkg.toml example
2+
#
3+
# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html
4+
# for detailed Gopkg.toml documentation.
5+
#
6+
# required = ["github.com/user/thing/cmd/thing"]
7+
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
8+
#
9+
# [[constraint]]
10+
# name = "github.com/user/project"
11+
# version = "1.0.0"
12+
#
13+
# [[constraint]]
14+
# name = "github.com/user/project2"
15+
# branch = "dev"
16+
# source = "github.com/myfork/project2"
17+
#
18+
# [[override]]
19+
# name = "github.com/x/y"
20+
# version = "2.4.0"
21+
#
22+
# [prune]
23+
# non-go = false
24+
# go-tests = true
25+
# unused-packages = true
26+
27+
28+
[[constraint]]
29+
name = "github.com/PuerkitoBio/goquery"
30+
version = "1.3.0"
31+
32+
[[constraint]]
33+
name = "github.com/boltdb/bolt"
34+
version = "1.3.1"
35+
36+
[[constraint]]
37+
name = "github.com/labstack/echo"
38+
version = "3.2.6"
39+
40+
[[constraint]]
41+
name = "github.com/sirupsen/logrus"
42+
version = "1.0.4"
43+
44+
[[constraint]]
45+
name = "github.com/spf13/pflag"
46+
version = "1.0.0"
47+
48+
[[constraint]]
49+
name = "github.com/spf13/viper"
50+
version = "1.0.0"
51+
52+
[[constraint]]
53+
name = "github.com/stretchr/testify"
54+
version = "1.2.1"
55+
56+
[prune]
57+
go-tests = true
58+
unused-packages = true

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import (
55
"net/http"
66
"path"
77

8-
log "github.com/Sirupsen/logrus"
98
"github.com/labstack/echo"
109
"github.com/labstack/echo/middleware"
10+
log "github.com/sirupsen/logrus"
1111
"github.com/spf13/pflag"
1212
"github.com/spf13/viper"
1313

server/activity.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,52 @@
11
package server
22

33
import (
4+
"net/http"
5+
"strings"
46
"time"
57
)
68

79
type Activity interface {
810
ActivityTime() time.Time
911
ActivityKey() uint32
1012
}
13+
14+
func ActivityFilterForRequest(r *http.Request) func(Activity) bool {
15+
subdomain := ""
16+
if r.Host != "" {
17+
subdomain = strings.Split(r.Host, ".")[0]
18+
}
19+
20+
includeReddit := false
21+
includeForumHost := map[string]bool{}
22+
23+
switch subdomain {
24+
case "br":
25+
includeForumHost["br.pathofexile.com"] = true
26+
case "ru":
27+
includeForumHost["ru.pathofexile.com"] = true
28+
case "th":
29+
includeForumHost["th.pathofexile.com"] = true
30+
case "de":
31+
includeForumHost["de.pathofexile.com"] = true
32+
case "fr":
33+
includeForumHost["fr.pathofexile.com"] = true
34+
case "es":
35+
includeForumHost["es.pathofexile.com"] = true
36+
default:
37+
includeReddit = true
38+
includeForumHost["www.pathofexile.com"] = true
39+
}
40+
41+
return func(a Activity) bool {
42+
switch a := a.(type) {
43+
case *ForumPost:
44+
return includeForumHost[a.Host]
45+
case *RedditComment:
46+
return includeReddit
47+
case *RedditPost:
48+
return includeReddit
49+
}
50+
return false
51+
}
52+
}

server/activity_handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type jsonResponse struct {
1616

1717
func ActivityHandler(db *Database) echo.HandlerFunc {
1818
return func(c echo.Context) error {
19-
activity, next := db.Activity(c.QueryParam("next"), 50)
19+
activity, next := db.Activity(c.QueryParam("next"), 50, ActivityFilterForRequest(c.Request()))
2020
response := jsonResponse{
2121
Next: next,
2222
}

0 commit comments

Comments
 (0)