/
server.go
56 lines (42 loc) · 1.1 KB
/
server.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
package main
import (
"fmt"
"net/http"
"os"
"github.com/RyotaKatoh/oreppoid/app"
"github.com/RyotaKatoh/oreppoid/app/filters"
"github.com/RyotaKatoh/oreppoid/config"
"github.com/RyotaKatoh/oreppoid/lib/server-helper/logging"
"github.com/Sirupsen/logrus"
"github.com/justinas/alice"
)
func getEnvVar(key, defaultVal string) string {
val := os.Getenv(key)
if len(val) == 0 {
val = defaultVal
}
return val
}
func main() {
logrus.SetLevel(logrus.DebugLevel)
mws := []alice.Constructor{
logging.NewHandler,
func(handler http.Handler) http.Handler { return filters.RenderSetupHandler(handler) },
}
appHandler := alice.New(mws...).Then(app.BuildRouter())
http.Handle("/", appHandler)
port := getEnvVar("PORT", config.DefaultServerPort)
addr := fmt.Sprintf(":%s", port)
logrus.Infof("Server listening on port %s", port)
http.ListenAndServe(addr, nil)
/*
twitterClient := twitter.NewTwitterClient()
v := url.Values{
"count": {"200"},
"include_rts": {"false"},
}
tweets := twitterClient.GetTweets(v)
mongoClient := &mongo.MongoClient{}
mongoClient.SaveTweet(tweets)
*/
}