-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
34 lines (27 loc) · 776 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 (
"database/sql"
"log"
"github.com/MarioSimou/crash-course-gin-gonic/internal/controllers"
"github.com/gin-gonic/gin"
_ "github.com/mattn/go-sqlite3"
)
func main() {
var router = gin.Default()
var address = ":3000"
var db *sql.DB
var e error
if db, e = sql.Open("sqlite3", "./data.db"); e != nil {
log.Fatalf("Error: %v", e)
}
defer db.Close()
if e := db.Ping(); e != nil {
log.Fatalf("Error: %v", e)
}
router.GET("/products", controllers.GetProducts(db))
router.GET("/products/:guid", controllers.GetProduct(db))
router.POST("/products", controllers.PostProduct(db))
router.DELETE("/products/:guid", controllers.DeleteProduct(db))
router.PUT("/products/:guid", controllers.PutProduct(db))
log.Fatalln(router.Run(address))
}