/
main.go
88 lines (71 loc) · 1.91 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package main
import (
"context"
"fmt"
"github.com/bykof/gostradamus"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"github.com/willie-lin/YEVER/configs"
"github.com/willie-lin/YEVER/pkg/database"
"github.com/willie-lin/YEVER/pkg/handler"
"go.uber.org/zap"
"net/http"
)
func main() {
log, _ := zap.NewDevelopment()
e := echo.New()
// Middleware
//e.Use(apmechov4.Middleware())
e.Use(middleware.Logger())
e.Use(middleware.Recover())
e.Use(middleware.RequestID())
//CORS
e.Use(middleware.CORSWithConfig(middleware.CORSConfig{
AllowOrigins: []string{"*"},
AllowMethods: []string{echo.GET, echo.HEAD, echo.PUT, echo.PATCH, echo.POST, echo.DELETE},
}))
//连接 数据库
client, err := database.NewClient()
//fmt.Println(client)
if err != nil {
log.Fatal("opening ent client", zap.Error(err))
return
}
defer client.Close()
//fmt.Println(client)
dateTime := gostradamus.Now()
fmt.Println(dateTime)
//defer client.Close()
ctx := context.Background()
//autoMigration := database.AutoMigration
autoMigration := database.AutoMigration
autoMigration(client, ctx)
//
//debugMode := database.DebugMode
debugMode := database.DebugMode
//
debugMode(err, client, ctx)
controller := &handler.Controller{Client: client}
// Server
// Routes
e.GET("/", hello)
e.GET("/users", handler.GetAllUser(client))
e.POST("/user", handler.CreateUser(client))
e.GET("/user/id", handler.FindUserByName(client))
e.DELETE("/user", handler.DeleteUser(client))
e.PUT("/user/name", handler.UpdateUserByName(client))
e.PUT("/user/id", handler.UpdateUserByID(client))
//e.PATCH("/user", handler.UpdateUser(client))
//e.POST("/user", )
e.POST("/user1", controller.InsertComment)
e.Static("/", "static/")
// Start server
e.Logger.Fatal(e.Start(":2022"))
}
// Handler
func hello(c echo.Context) error {
return c.String(http.StatusOK, "Hello, World!")
}
func init() {
configs.InitConfig()
}