-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
43 lines (36 loc) · 1.03 KB
/
main.go
File metadata and controls
43 lines (36 loc) · 1.03 KB
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
package main
import (
"log"
"net/http"
"time"
jwt "github.com/dgrijalva/jwt-go"
"github.com/nathanmalishev/go_api_example/common"
"github.com/nathanmalishev/go_api_example/models"
mgo "gopkg.in/mgo.v2"
)
func main() {
/* create data store for the app */
store := models.CreateStore(&mgo.DialInfo{
Addrs: []string{common.AppConfig.MongoServer},
Username: common.AppConfig.MongoUsername,
Database: common.AppConfig.DbName,
Password: common.AppConfig.MongoPassword,
Timeout: time.Second * 5,
}, common.AppConfig.DbName)
/* initialize indexs */
err := store.InitIndexs()
if err != nil {
log.Fatal(err)
}
/* create authorizer used to decode/encode jwt's */
authModule := &common.Auth{
Secret: common.AppConfig.JwtSecret,
SigningMethod: jwt.SigningMethodHS512,
}
server := &http.Server{
Addr: common.AppConfig.Server,
Handler: InitRoutes(store, authModule), // routes needs a copy of the store && authModule
}
log.Println("Listening on ", common.AppConfig.Server)
log.Fatal(server.ListenAndServe())
}