-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
70 lines (54 loc) · 1.64 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"fmt"
"log"
inspectController "github.com/lewy9109/autoNotes/pkg-Inspection/controller"
"github.com/lewy9109/autoNotes/pkg-Inspection/inspection"
"github.com/lewy9109/autoNotes/pkg-User/controller/userController"
"github.com/lewy9109/autoNotes/pkg-User/user"
"github.com/gin-gonic/gin"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
)
func main() {
db, err := gorm.Open(sqlite.Open("database.db"), &gorm.Config{})
if err != nil {
log.Fatal(err)
}
err = db.AutoMigrate(&inspection.ReguralCarInspection{})
if err != nil {
log.Fatal(err)
}
err = db.AutoMigrate(&user.User{})
if err != nil {
log.Fatal(err)
}
startHttpServer(db)
}
func startHttpServer(db *gorm.DB) {
inspectionRepo := inspection.NewRepository(db)
inspectionService := inspection.NewService(inspectionRepo)
inspectCarController := inspectController.New(inspectionService)
userInfra := user.NewUserInfrastructure(db)
userService := user.NewUserService(userInfra, "secretToken")
userServer := userController.NewUserServer(userService)
router := gin.Default()
fmt.Println("Starting HTTP on port 8080 ...")
groupUser := router.Group("/user/", userServer.Authorize)
{
groupUser.GET("/", userServer.GetInfo)
}
router.POST("/users", userServer.CreateUser)
router.POST("/login", userServer.LoginUser)
inspectCarGroup := router.Group("/inspect", userServer.Authorize)
{
inspectCarGroup.POST("/", inspectCarController.CreateInseption)
inspectCarGroup.GET("/", inspectCarController.GetListInspections)
inspectCarGroup.GET("/:id", inspectCarController.GetInspectionById)
}
err := router.Run(":9889")
if err != nil {
log.Fatalln(err)
return
}
}