-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
41 lines (33 loc) · 1.07 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
package main
import (
"github.com/go-playground/validator/v10"
_ "github.com/go-sql-driver/mysql"
"github.com/julienschmidt/httprouter"
"gohttp/apirest"
"gohttp/config"
"gohttp/repository"
"gohttp/service"
"gohttp/utils/exception"
"gohttp/utils/helper"
"net/http"
)
func main() {
db := config.NewDB()
validate := validator.New()
categoryRepository := repository.NewCategoryRepositoryImpl()
categoryService := service.NewCategoryServiceImpl(categoryRepository, db, validate)
categoryRest := apirest.NewCategoryRestImpl(categoryService)
router := httprouter.New()
router.GET("/internal/api/categories", categoryRest.FindAll)
router.POST("/internal/api/categories", categoryRest.Create)
router.GET("/internal/api/categories/:catId", categoryRest.FindById)
router.PUT("/internal/api/categories/:catId", categoryRest.Update)
router.DELETE("/internal/api/categories/:catId", categoryRest.Delete)
router.PanicHandler = exception.ErrorHandler
server := http.Server{
Addr: "localhost:3000",
Handler: router,
}
err := server.ListenAndServe()
helper.PanicIfError(err)
}