forked from gocastsian/adamak
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
31 lines (25 loc) · 886 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
package main
import (
"github.com/gocastsian/adamak/adapter/store"
v1 "github.com/gocastsian/adamak/delivery/http/v1"
"github.com/gocastsian/adamak/validator"
"github.com/labstack/echo/v4"
)
func main() {
dsn := "adamak_user:adamak_pass@tcp(127.0.0.1:3306)/adamak?charset=utf8mb4&parseTime=True&loc=Local"
// connect to database and auto migrate
mysqlStore := store.New(dsn)
// setup http server and router
e := echo.New()
// add routes
e.GET("/users", v1.FindUsers(mysqlStore))
e.POST("/users", v1.CreateUser(mysqlStore,
validator.ValidateCreateUser))
e.GET("/users/:id", v1.FindUser(mysqlStore,
validator.ValidateFindUser(mysqlStore)))
e.PATCH("/users/:id", v1.UpdateUser(mysqlStore,
validator.ValidateUpdateUser(mysqlStore)))
e.DELETE("/users/:id", v1.DeleteUser(mysqlStore,
validator.ValidateDeleteUser(mysqlStore)))
e.Logger.Fatal(e.Start(":8080"))
}