-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.go
62 lines (46 loc) · 1.14 KB
/
app.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
package main
import (
"fmt"
"log"
"net/http"
"os"
"github.com/nararya-anugraha/big-project/nsq"
gcfg "gopkg.in/gcfg.v1"
"github.com/julienschmidt/httprouter"
"github.com/nararya-anugraha/big-project/db"
"github.com/nararya-anugraha/big-project/redis"
"github.com/nararya-anugraha/big-project/user"
"github.com/nararya-anugraha/big-project/visitor"
)
type ConfigType struct {
Database db.DatabaseConfigType
Redis redis.RedisConfigType
NSQ nsq.NSQConfigType
}
func main() {
os.Exit(Main())
}
func Main() int {
config := ConfigType{}
gcfg.ReadFileInto(&config, "config.ini")
db, err := db.GetDB(&config.Database)
if err != nil {
log.Panic(err.Error())
}
redisClient := redis.GetRedisClient(&config.Redis)
nsqConsumer, err := nsq.CreateConsumer(&config.NSQ)
if err != nil {
log.Panic(err.Error())
}
nsqProducer, err := nsq.CreateProducer(&config.NSQ)
if err != nil {
log.Panic(err.Error())
}
router := httprouter.New()
user.Wire(router, db)
visitor.Wire(router, redisClient, nsqConsumer, nsqProducer)
go nsqConsumer.Run()
log.Fatal(http.ListenAndServe(":8080", router))
fmt.Println("App Started")
return 0
}