PaulPaulAga

Untitled

Apr 9th, 2021
359
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package server
  2.  
  3. import (
  4.     "Redioteka/internal/pkg/database"
  5.     "Redioteka/internal/pkg/middlewares"
  6.     _movieHandler "Redioteka/internal/pkg/movie/delivery/http"
  7.     _movieRepository "Redioteka/internal/pkg/movie/repository"
  8.     _movieUsecase "Redioteka/internal/pkg/movie/usecase"
  9.     _userHandler "Redioteka/internal/pkg/user/delivery/http"
  10.     _userRepository "Redioteka/internal/pkg/user/repository"
  11.     _userUsecase "Redioteka/internal/pkg/user/usecase"
  12.     "Redioteka/internal/pkg/utils/log"
  13.     "Redioteka/internal/pkg/utils/session"
  14.     "fmt"
  15.     "github.com/gorilla/mux"
  16.     "net/http"
  17.     "os"
  18.     "os/signal"
  19.     "syscall"
  20. )
  21.  
  22. func RunServer(addr string) {
  23.     r := mux.NewRouter()
  24.     s := r.PathPrefix("/api").Subrouter()
  25.  
  26.     middL := middlewares.InitMiddleware()
  27.     r.Use(middL.PanicRecoverMiddleware)
  28.     s.Use(middL.CORSMiddleware)
  29.     s.Use(middL.LoggingMiddleware)
  30.  
  31.     userRepo := _userRepository.NewMapUserRepository()
  32.     movieRepo := _movieRepository.NewMapMovieRepository()
  33.  
  34.     userUsecase := _userUsecase.NewUserUsecase(userRepo)
  35.     movieUsecase := _movieUsecase.NewMovieUsecase(movieRepo)
  36.  
  37.     _userHandler.NewUserHandlers(s, userUsecase)
  38.     _movieHandler.NewMovieHandlers(s, movieUsecase)
  39.  
  40.     // Static files
  41.     fileRouter := r.PathPrefix("/static").Subrouter()
  42.     NewFileHandler(fileRouter)
  43.  
  44.     server := http.Server{
  45.         Addr:    addr,
  46.         Handler: r,
  47.     }
  48.  
  49.     log.Log.Debug(fmt.Sprint("starting server at ", addr))
  50.  
  51.     err := server.ListenAndServe()
  52.     if err != nil {
  53.         log.Log.Error(err)
  54.     }
  55. }
  56.  
  57. func closeConnections(db *database.DBManager) {
  58.     session.Destruct()
  59.     database.Disconnect(db)
  60. }
  61.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×