From 530896a015a09edccfdf5eed528733f4756a191d Mon Sep 17 00:00:00 2001 From: Sergey Petrov Date: Mon, 14 Apr 2025 11:51:02 +0500 Subject: [PATCH] Refactoring. --- reader/cmd/main.go | 26 ++++++++++++++++---------- reader/go.mod | 2 +- reader/internal/handlers/handlers.go | 7 ++++--- reader/internal/log/logger.go | 2 +- reader/internal/unpacker/proc.go | 6 +++--- 5 files changed, 25 insertions(+), 18 deletions(-) diff --git a/reader/cmd/main.go b/reader/cmd/main.go index 1ee46e7..0c3b5a8 100644 --- a/reader/cmd/main.go +++ b/reader/cmd/main.go @@ -1,10 +1,16 @@ package main import ( + "fmt" + "os" + + "git.insit.tech/psa/rtsp_reader-writer/reader/internal/config" + "git.insit.tech/psa/rtsp_reader-writer/reader/internal/handlers" + logger "git.insit.tech/psa/rtsp_reader-writer/reader/internal/log" + "git.insit.tech/psa/rtsp_reader-writer/reader/internal/metrics" jwtware "github.com/gofiber/contrib/jwt" "github.com/gofiber/fiber/v2" "github.com/sirupsen/logrus" - "reader/internal/handlers" ) func main() { @@ -18,14 +24,14 @@ func main() { // //log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", port), nil)) - //go metrics.Metrics() - //logger.StartMainLogger(config.Local, "reader") - // - //// Check if the data folder in the directory. - //homeDir, err := os.UserHomeDir() - //if err != nil { - //} - //config.DirData = fmt.Sprintf("%s/%s/vod", homeDir, config.Local) + go metrics.Metrics() + logger.StartMainLogger(config.Local, "reader") + + // Check if the data folder in the directory. + homeDir, err := os.UserHomeDir() + if err != nil { + } + config.DirData = fmt.Sprintf("%s/%s/vod", homeDir, config.Local) // //err = unpacker.CreateVideo() //if err != nil { @@ -34,7 +40,7 @@ func main() { app := fiber.New() - authStorage := &handlers.AuthStorage{map[string]handlers.User{}} + authStorage := &handlers.AuthStorage{Users: map[string]handlers.User{}} authHandler := &handlers.AuthHandler{Storage: authStorage} userHandler := &handlers.UserHandler{Storage: authStorage} diff --git a/reader/go.mod b/reader/go.mod index 47328d2..1024035 100644 --- a/reader/go.mod +++ b/reader/go.mod @@ -1,4 +1,4 @@ -module reader +module git.insit.tech/psa/rtsp_reader-writer/reader go 1.24.1 diff --git a/reader/internal/handlers/handlers.go b/reader/internal/handlers/handlers.go index e5e1cda..00ca4cb 100644 --- a/reader/internal/handlers/handlers.go +++ b/reader/internal/handlers/handlers.go @@ -4,7 +4,6 @@ import ( "encoding/json" "errors" "fmt" - jwtware "github.com/gofiber/contrib/jwt" "log" "net/http" "os" @@ -12,12 +11,13 @@ import ( "strings" "time" + "git.insit.tech/psa/rtsp_reader-writer/reader/internal/config" + "git.insit.tech/psa/rtsp_reader-writer/reader/internal/processor" "git.insit.tech/psa/rtsp_reader-writer/writer/pkg/storage" + jwtware "github.com/gofiber/contrib/jwt" "github.com/gofiber/fiber/v2" "github.com/golang-jwt/jwt/v5" "github.com/sirupsen/logrus" - "reader/internal/config" - "reader/internal/processor" ) type VideoRequest struct { @@ -168,6 +168,7 @@ func ListVodsHandler(c *fiber.Ctx) error { // Read directory. entries, err := os.ReadDir(config.DirData) if err != nil { + log.Println("StatusInternalServerError") return c.SendStatus(fiber.StatusInternalServerError) } diff --git a/reader/internal/log/logger.go b/reader/internal/log/logger.go index 999db39..f06aac9 100644 --- a/reader/internal/log/logger.go +++ b/reader/internal/log/logger.go @@ -5,9 +5,9 @@ import ( "strconv" "time" + "git.insit.tech/psa/rtsp_reader-writer/reader/internal/config" log2 "git.insit.tech/sas/rtsp_proxy/core/log" "go.uber.org/zap" - "reader/internal/config" ) var ( diff --git a/reader/internal/unpacker/proc.go b/reader/internal/unpacker/proc.go index 09c6245..9ce8df5 100644 --- a/reader/internal/unpacker/proc.go +++ b/reader/internal/unpacker/proc.go @@ -8,18 +8,18 @@ import ( "io" "log" "os" - "reader/internal/config" "strconv" "strings" "time" + "git.insit.tech/psa/rtsp_reader-writer/reader/internal/config" + logger "git.insit.tech/psa/rtsp_reader-writer/reader/internal/log" + "git.insit.tech/psa/rtsp_reader-writer/reader/internal/processor" "git.insit.tech/psa/rtsp_reader-writer/writer/pkg/storage" "git.insit.tech/sas/rtsp_proxy/core/gen" log2 "git.insit.tech/sas/rtsp_proxy/core/log" "github.com/bluenviron/gortsplib/v4/pkg/format" "go.uber.org/zap" - logger "reader/internal/log" - "reader/internal/processor" ) // CreateVideo generate TS files and M3U8 playlists.