-
Notifications
You must be signed in to change notification settings - Fork 9
/
server.go
35 lines (28 loc) · 878 Bytes
/
server.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
package main
import (
"fmt"
"log"
"github.com/gin-contrib/gzip"
"github.com/gin-gonic/gin"
"github.com/lakshanwd/go-crud/handler"
"github.com/lakshanwd/go-crud/repository"
)
func main() {
fmt.Println("setup database connections")
if err := repository.SetupRepo(); err != nil {
log.Fatal(err)
}
defer repository.CloseRepo()
fmt.Println("handling roures")
router := gin.Default()
router.Use(gzip.Gzip(gzip.DefaultCompression))
router.GET("/book", handler.BookGetHandler)
router.POST("/book", handler.BookPostHandler)
router.PUT("/book", handler.BookPutHandler)
router.DELETE("/book/:id", handler.BookDeleteHandler)
router.GET("/student", handler.StudentGetHandler)
router.POST("/student", handler.StudentPostHandler)
router.PUT("/student", handler.StudentPutHandler)
router.DELETE("/student/:id", handler.StudentDeleteHandler)
router.Run(":8080")
}