-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
37 lines (28 loc) · 767 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
35
36
37
package main
import (
"books/controller"
"books/lib"
"fmt"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
)
func main() {
config := lib.LoadConfig()
logging := lib.LoadLogging()
url := fmt.Sprintf("%s:%d", config.Server.Host, config.Server.Port)
db, err := lib.LoadDatabase()
if err != nil {
panic(err)
}
ctrl := controller.New(db)
logging.Info().Msgf("[CONFIG] %v", config)
logging.Info().Msgf("[APP] Started at http://%s/", url)
route := gin.Default()
route.Use(cors.Default())
route.POST("/book/create", ctrl.CreateBook)
route.GET("/books", ctrl.ReadBooks)
route.GET("/book/:bookId", ctrl.ReadBook)
route.PUT("/book/update/:bookId", ctrl.UpdateBook)
route.DELETE("/book/delete/:bookId", ctrl.DeleteBook)
route.Run(url)
}