-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
44 lines (34 loc) · 1.25 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
package main
import (
"dsrizki/golang-restful-api/app"
"dsrizki/golang-restful-api/controller"
"dsrizki/golang-restful-api/exception"
"dsrizki/golang-restful-api/helper"
"dsrizki/golang-restful-api/middleware"
"dsrizki/golang-restful-api/repository"
"dsrizki/golang-restful-api/service"
"net/http"
_ "github.com/go-sql-driver/mysql"
"github.com/go-playground/validator/v10"
"github.com/julienschmidt/httprouter"
)
func main() {
db := app.NewDB()
validate := validator.New()
categoryRepository := repository.NewCategoryRepository()
categoryService := service.NewCategoryService(categoryRepository, db, validate)
categoryController := controller.NewCategoryController(categoryService)
router := httprouter.New()
router.GET("/api/categories", categoryController.FindAll)
router.GET("/api/categories/:categoryId", categoryController.FindById)
router.POST("/api/categories", categoryController.Create)
router.PUT("/api/categories/:categoryId", categoryController.Update)
router.DELETE("/api/categories/:categoryId", categoryController.Delete)
router.PanicHandler = exception.ErrorHandler
server := http.Server{
Addr: "localhost:3000",
Handler: middleware.NewAuthMiddleware(router),
}
err := server.ListenAndServe()
helper.PanicIfError(err)
}