forked from ccbrown/gggtracker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
67 lines (58 loc) · 1.77 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
import (
"fmt"
"strings"
"github.com/aws/aws-sdk-go-v2/aws/external"
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
log "github.com/sirupsen/logrus"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"github.com/ccbrown/gggtracker/server"
)
func main() {
pflag.IntP("port", "p", 8080, "the port to listen on")
pflag.String("staticdir", "", "this argument is ignored and will be removed")
pflag.String("ga", "", "a google analytics account")
pflag.String("db", "./gggtracker.db", "the database file path")
pflag.String("dynamodb-table", "", "if given, DynamoDB will be used instead of a database file")
pflag.String("forumsession", "", "the POESESSID cookie for a forum session")
viper.BindPFlags(pflag.CommandLine)
pflag.Parse()
viper.SetEnvPrefix("gggtracker")
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
viper.AutomaticEnv()
var db server.Database
var err error
if tableName := viper.GetString("dynamodb-table"); tableName != "" {
config, err := external.LoadDefaultAWSConfig()
if err != nil {
log.Fatal(err)
}
db, err = server.NewDynamoDBDatabase(dynamodb.New(config), tableName)
} else {
db, err = server.NewBoltDatabase(viper.GetString("db"))
}
if err != nil {
log.Fatal(err)
}
defer db.Close()
redditIndexer, err := server.NewRedditIndexer(server.RedditIndexerConfiguration{
Database: db,
})
if err != nil {
log.Fatal(err)
}
defer redditIndexer.Close()
if viper.GetString("forumsession") != "" {
forumIndexer, err := server.NewForumIndexer(server.ForumIndexerConfiguration{
Database: db,
Session: viper.GetString("forumsession"),
})
if err != nil {
log.Fatal(err)
}
defer forumIndexer.Close()
}
e := server.New(db, viper.GetString("ga"))
log.Fatal(e.Start(fmt.Sprintf(":%v", viper.GetInt("port"))))
}