refactor #6
4 changed files with 34 additions and 20 deletions
|
@ -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)
|
||||
|
|
27
internal/config/config.go
Normal file
27
internal/config/config.go
Normal file
|
@ -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
|
||||
}
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue