diff --git a/cmd/aides-repo-api/main.go b/cmd/aides-repo-api/main.go index 94f63f5..6ae3bf4 100644 --- a/cmd/aides-repo-api/main.go +++ b/cmd/aides-repo-api/main.go @@ -4,19 +4,15 @@ import ( "log" "net/http" - "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/models" + "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/config" "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/router" - - "github.com/caarlos0/env/v11" ) func main() { - var config models.Config - if err := env.Parse(&config); err != nil { - log.Fatalf("ошибка при парсинге переменных %v", err) - } + config := config.New() + // Конфигурация сервера - router := router.NewRouter(config).SetupRoutes() + router := router.NewRouter(*config).SetupRoutes() log.Printf("Сервер запущен на порту: %s", config.Port) http.ListenAndServe(":"+config.Port, router) diff --git a/internal/config/config.go b/internal/config/config.go new file mode 100644 index 0000000..43cc47c --- /dev/null +++ b/internal/config/config.go @@ -0,0 +1,27 @@ +package config + +import ( + "log" + + "github.com/caarlos0/env/v11" +) + +type Config struct { + Token string `env:"TOKEN"` + Repo string `env:"REPO"` + UploadDir string `env:"UPLOAD_DIR" envDefault:"./uploads"` + TaskDir string `env:"TASK_DIR" envDefault:"./tasks"` + SymLink string `env:"SYM_LINK"` + Port string `env:"PORT" envDefault:"8080"` + MaxSizeUpload int64 `env:"MAX_SIZE_UPLOAD" envDefault:"104857600"` //100 MB +} + +func New() *Config { + config := new(Config) + + if err := env.Parse(config); err != nil { + log.Fatalf("ошибка при парсинге переменных %v", err) + } + + return config +} diff --git a/internal/models/models.go b/internal/models/models.go index cd7de19..f923486 100644 --- a/internal/models/models.go +++ b/internal/models/models.go @@ -1,15 +1,5 @@ package models -type Config struct { - Token string `env:"TOKEN"` - Repo string `env:"REPO"` - UploadDir string `env:"UPLOAD_DIR" envDefault:"./uploads"` - TaskDir string `env:"TASK_DIR" envDefault:"./tasks"` - SymLink string `env:"SYM_LINK"` - Port string `env:"PORT" envDefault:"8080"` - MaxSizeUpload int64 `env:"MAX_SIZE_UPLOAD" envDefault:"104857600"` //100 MB -} - type FileUpload struct { TaskID string diff --git a/internal/router/router.go b/internal/router/router.go index 42c5c1c..928326c 100644 --- a/internal/router/router.go +++ b/internal/router/router.go @@ -9,6 +9,7 @@ import ( "path" "strconv" + "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/config" "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/models" "github.com/go-chi/render" @@ -32,11 +33,11 @@ func createSymlink(target, link string) error { } type Router struct { - Config models.Config + Config config.Config } // Создает Роутер -func NewRouter(cfg models.Config) *Router { +func NewRouter(cfg config.Config) *Router { return &Router{Config: cfg} }