-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
58 lines (47 loc) · 1.16 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
package main
import (
"go-mono/configs"
"go-mono/router"
"net/http"
"github.com/go-playground/validator"
"github.com/labstack/echo/v4"
)
type (
CustomValidator struct {
validator *validator.Validate
}
)
func (cv *CustomValidator) Validate(i interface{}) error {
if err := cv.validator.Struct(i); err != nil {
// Optionally, you could return the error to give each route more control over the status code
return echo.NewHTTPError(http.StatusBadRequest, err.Error())
}
return nil
}
// func handler(c *dandelion.Context) error {
// req := c.Request()
// fmt.Println(c, req)
// return c.JSON()
// }
func init() {
configs.LoadEnv()
}
func main() {
configs.ConnectDB("mysql")
// echo version
e := echo.New()
e.Validator = &CustomValidator{validator: validator.New()}
e.Static("/static", "static")
router.Route(*e)
const PORT = ":8080"
e.Logger.Fatal(e.Start(PORT))
// experimental feature
// r := dandelion.NewRouter()
// r.Route("GET", "/test", handler)
// r.Route("GET", "/test2",
// func(w http.ResponseWriter, r *http.Request) {
// message := "test"
// w.Write([]byte("Hello " + message))
// })
// http.ListenAndServe(":8000", dr)
}