-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
58 lines (50 loc) · 1.3 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 (
"log"
"net/http"
"os"
"reflect"
"strings"
"xsis-test/config"
"xsis-test/repository"
"xsis-test/services"
"github.com/go-playground/validator/v10"
"github.com/joho/godotenv"
"github.com/labstack/echo/v4"
)
func init() {
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
}
config.ConnectDB()
}
func MovieInjector() (service services.MovieServiceContract) {
movieRepository := repository.NewMovieRepository(config.DB)
service = services.NewMovieService(movieRepository)
return
}
func main() {
e := echo.New()
// register validator
val := validator.New()
val.RegisterTagNameFunc(func(fld reflect.StructField) string {
name := strings.SplitN(fld.Tag.Get("json"), ",", 2)[0]
if name == "-" {
return ""
}
return name
})
e.Validator = &config.Validator{Validator: val}
e.GET("/", func(c echo.Context) error {
return c.String(http.StatusOK, "Hello, World!")
})
movieService := MovieInjector()
e.GET("/Movies", movieService.GetMovies)
e.POST("/upload-image", movieService.UploadImage)
e.POST("/Movies", movieService.CreateMovie)
e.GET("/Movies/:ID", movieService.GetDetailMovie)
e.PATCH("/Movies/:ID", movieService.UpdateMovie)
e.DELETE("/Movies/:ID", movieService.DeleteMovie)
e.Logger.Fatal(e.Start(":" + os.Getenv("APP_PORT")))
}