forked from awize/movies-searcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
68 lines (63 loc) · 1.72 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
59
60
61
62
63
64
65
66
67
68
package main
import (
"crypto/tls"
"encoding/csv"
"fmt"
"net/http"
"os"
"path/filepath"
"strconv"
"github.com/awize/movies-searcher/config"
"github.com/awize/movies-searcher/controller"
"github.com/awize/movies-searcher/router"
"github.com/awize/movies-searcher/service"
usecase "github.com/awize/movies-searcher/usecase/movie"
"github.com/gin-gonic/gin"
"github.com/go-resty/resty/v2"
"github.com/spf13/viper"
)
func main() {
public := viper.New()
public.SetConfigFile(config.ConfigFile)
if err := public.ReadInConfig(); err != nil {
fmt.Println(err)
}
config := &config.Config{}
fmt.Println(public.AllKeys())
err := public.Unmarshal(config)
if err != nil {
fmt.Println(err)
}
fmt.Println("config:", config)
workspaceDir, err := os.Getwd()
if err != nil {
fmt.Println(err)
}
fileNameAbs := filepath.Join(workspaceDir, config.MoviesFileName)
fileR, err := os.Open(fileNameAbs)
if err != nil {
fmt.Println(err)
}
fileW, err := os.OpenFile(fileNameAbs, os.O_APPEND|os.O_WRONLY, os.ModeAppend)
if err != nil {
fmt.Println(err)
}
defer fileR.Close()
defer fileW.Close()
client := resty.New()
client.SetTLSClientConfig(&tls.Config{InsecureSkipVerify: true})
csvr := csv.NewReader(fileR)
csvw := csv.NewWriter(fileW)
movieService := service.NewMoviesService(fileR, csvr, csvw, client, config)
movieUseCase := usecase.NewMovieUsecase(movieService)
movieController := controller.NewMovieController(movieUseCase)
r := gin.Default()
router.MakeMovieHandlers(r, movieController)
// TODO: Change to api stats
r.GET("/healthcheck", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"message": "Working"})
})
r.Run(":" + strconv.Itoa(config.Port))
}
// Viper -- set config file - file nameyaml
// validator