-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
57 lines (44 loc) · 1.8 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
package main
import (
"github.com/go-playground/validator"
_ "github.com/go-sql-driver/mysql"
"github.com/julienschmidt/httprouter"
"go.uber.org/zap"
"net/http"
_categoryHandler "yuuki/app/category/delivery/http"
_categoryRepo "yuuki/app/category/repository"
_categoryUsecase "yuuki/app/category/usecase"
"yuuki/app/mariadb"
_shortenerHandler "yuuki/app/shortener/delivery/http"
_shortenerRepo "yuuki/app/shortener/repository"
_shortenerUsecase "yuuki/app/shortener/usecase"
_uploadHandler "yuuki/app/upload/delivery/http"
_uploadRepo "yuuki/app/upload/repository"
_uploadUsecase "yuuki/app/upload/usecase"
"yuuki/middleware"
"yuuki/pkg/config"
"yuuki/pkg/exception"
"yuuki/pkg/helper"
)
func main() {
configuration := config.NewConfiguration(`./.env`)
database := mariadb.GetConnection(configuration)
validate := validator.New()
categoryRepository := _categoryRepo.NewCategoryRepository(database)
categoryUsecase := _categoryUsecase.NewCategoryUsecase(categoryRepository, validate)
uploadRepository := _uploadRepo.NewUploadRepository(database)
uploadUsecase := _uploadUsecase.NewUploadUsecase(uploadRepository)
shortenerRepository := _shortenerRepo.NewShortenerRepository(database)
shortenerUsecase := _shortenerUsecase.NewShortenerUsecase(shortenerRepository, validate)
logger, err := zap.NewProduction()
helper.PanicIfErr(err)
defer logger.Sync()
sugar := logger.Sugar()
router := httprouter.New()
router.PanicHandler = exception.ErrorHandler
_categoryHandler.RegisterCategoryHandler(router, categoryUsecase)
_uploadHandler.RegisterUploadHandler(router, uploadUsecase)
_shortenerHandler.RegisterShortenerHandler(router, shortenerUsecase)
sugar.Infow("listening and serving http on :8080")
sugar.Fatal(http.ListenAndServe(":8080", &middleware.LogMiddleware{Handler: router, Logger: sugar}))
}