-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
34 lines (27 loc) · 788 Bytes
/
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
package main
import (
"log"
"net/http"
"github.com/joho/godotenv"
"github.com/julienschmidt/httprouter"
"github.com/ianlofs/go_rest_api/constants"
"github.com/ianlofs/go_rest_api/controllers"
"github.com/ianlofs/go_rest_api/database"
"github.com/ianlofs/go_rest_api/middleware"
)
func main() {
godotenv.Load()
// initialize private/public keys, db connection info, etc
constants.InitConstants()
db, err := database.New()
if err != nil {
log.Fatalln(err)
}
db.SetMaxOpenConns(40)
defer db.Close()
r := httprouter.New()
r.POST("/register", controllers.Register(db))
r.POST("/login", controllers.Login(db))
r.GET("/user/:username", middleware.AuthRequest(controllers.GetUser(db)))
log.Fatal(http.ListenAndServe(":" + constants.Port, r))
}