-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
53 lines (43 loc) · 1.39 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
package main
import (
"library/APIHandlers"
"library/Authenticate"
"library/config"
"library/db"
"net/http"
"github.com/ilyakaznacheev/cleanenv"
"github.com/sirupsen/logrus"
)
func main() {
logger := logrus.New()
var config config.Config
err := cleanenv.ReadEnv(&config)
if err != nil {
logger.WithError(err).Panicln("Can not read config file")
}
InitDB, err := db.InitDB(config)
if err != nil {
logger.WithError(err).Fatalln("Can not Create datatbase")
}
logger.Infoln("Connected to datatbase successfully")
err = InitDB.CreateSchemas()
if err != nil {
logger.WithError(err).Fatalln("Can not migrate tables and models")
}
logger.Infoln("automigrate successfully")
auth, err := Authenticate.NewAuth(InitDB, 10, logger)
if err != nil {
logger.WithError(err).Fatal("can not create the authenticate instance")
}
bookManagerServer := APIHandlers.Server{
Authenticate: auth,
DB: InitDB,
Logger: logger,
}
http.HandleFunc("/api/v1/auth/signup", bookManagerServer.HandleSignupAPI)
http.HandleFunc("/api/v1/auth/login", bookManagerServer.HandleLogin)
http.HandleFunc("/api/v1/books", bookManagerServer.HandleCreateAndGetAllBook)
http.HandleFunc("/api/v1/books/", bookManagerServer.HandleUpdateAndDEleteAndGetBook)
http.HandleFunc("/profile", bookManagerServer.HandleProfile)
logger.WithError(http.ListenAndServe(":8080", nil)).Fatalln("can not setup the server")
}