style: add formatters
This commit is contained in:
parent
f077ffd7a7
commit
b16650ec62
10 changed files with 63 additions and 24 deletions
14
Makefile
Normal file
14
Makefile
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
GOFUMPT := go run mvdan.cc/gofumpt@v0.7.0
|
||||||
|
GOIMPORTS := go run golang.org/x/tools/cmd/goimports@v0.28.0
|
||||||
|
GCI := go run github.com/daixiang0/gci@v0.13.5
|
||||||
|
GOLINES := go run github.com/segmentio/golines@v0.12.2
|
||||||
|
|
||||||
|
format:
|
||||||
|
@echo "🛠️ Format code"
|
||||||
|
$(GOIMPORTS) -w .
|
||||||
|
$(GCI) write -s standard -s default -s "prefix(code.alt-gnome.ru/aides-infra/aides-repo-api)" .
|
||||||
|
$(GOLINES) -w .
|
||||||
|
$(GOFUMPT) -w .
|
||||||
|
@echo "✅ Format done."
|
||||||
|
|
||||||
|
.PHONY: format
|
|
@ -5,6 +5,9 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"gorm.io/driver/postgres"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
|
||||||
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/config"
|
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/config"
|
||||||
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/controllers/taskcontroller"
|
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/controllers/taskcontroller"
|
||||||
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/models"
|
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/models"
|
||||||
|
@ -12,8 +15,6 @@ import (
|
||||||
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/services/cronservice"
|
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/services/cronservice"
|
||||||
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/services/reposervice"
|
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/services/reposervice"
|
||||||
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/services/taskservice"
|
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/services/taskservice"
|
||||||
"gorm.io/driver/postgres"
|
|
||||||
"gorm.io/gorm"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type App struct {
|
type App struct {
|
||||||
|
@ -29,7 +30,14 @@ type App struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func createDBConnection(cfg *config.Config) (*gorm.DB, error) {
|
func createDBConnection(cfg *config.Config) (*gorm.DB, error) {
|
||||||
dsn := fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s sslmode=disable", cfg.DBHost, cfg.DBPort, cfg.DBUser, cfg.DBPassword, cfg.DBName)
|
dsn := fmt.Sprintf(
|
||||||
|
"host=%s port=%s user=%s password=%s dbname=%s sslmode=disable",
|
||||||
|
cfg.DBHost,
|
||||||
|
cfg.DBPort,
|
||||||
|
cfg.DBUser,
|
||||||
|
cfg.DBPassword,
|
||||||
|
cfg.DBName,
|
||||||
|
)
|
||||||
return gorm.Open(postgres.Open(dsn), &gorm.Config{})
|
return gorm.Open(postgres.Open(dsn), &gorm.Config{})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,15 +8,15 @@ import (
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Token string `env:"TOKEN"`
|
Token string `env:"TOKEN"`
|
||||||
UploadDir string `env:"UPLOAD_DIR" envDefault:"./uploads"`
|
UploadDir string `env:"UPLOAD_DIR" envDefault:"./uploads"`
|
||||||
Port string `env:"PORT" envDefault:"8080"`
|
Port string `env:"PORT" envDefault:"8080"`
|
||||||
MaxSizeUpload int64 `env:"MAX_SIZE_UPLOAD" envDefault:"104857600"` //100 MB
|
MaxSizeUpload int64 `env:"MAX_SIZE_UPLOAD" envDefault:"104857600"` // 100 MB
|
||||||
|
|
||||||
DBHost string `env:"DB_HOST" envDefault:"localhost"`
|
DBHost string `env:"DB_HOST" envDefault:"localhost"`
|
||||||
DBPort string `env:"DB_PORT" envDefault:"5432"`
|
DBPort string `env:"DB_PORT" envDefault:"5432"`
|
||||||
DBUser string `env:"DB_USER" envDefault:"user"`
|
DBUser string `env:"DB_USER" envDefault:"user"`
|
||||||
DBPassword string `env:"DB_PASSWORD" envDefault:"password"`
|
DBPassword string `env:"DB_PASSWORD" envDefault:"password"`
|
||||||
DBName string `env:"DB_NAME" envDefault:"app_db"`
|
DBName string `env:"DB_NAME" envDefault:"app_db"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func New() *Config {
|
func New() *Config {
|
||||||
|
|
|
@ -4,9 +4,10 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/go-chi/render"
|
||||||
|
|
||||||
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/common/errors"
|
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/common/errors"
|
||||||
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/models"
|
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/models"
|
||||||
"github.com/go-chi/render"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type CreateTaskDTO struct {
|
type CreateTaskDTO struct {
|
||||||
|
|
|
@ -4,10 +4,11 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/common/errors"
|
|
||||||
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/services/taskservice"
|
|
||||||
"github.com/go-chi/chi/v5"
|
"github.com/go-chi/chi/v5"
|
||||||
"github.com/go-chi/render"
|
"github.com/go-chi/render"
|
||||||
|
|
||||||
|
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/common/errors"
|
||||||
|
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/services/taskservice"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TaskUploadResponse struct {
|
type TaskUploadResponse struct {
|
||||||
|
|
|
@ -3,9 +3,10 @@ package middlewares
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/go-chi/render"
|
||||||
|
|
||||||
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/common/errors"
|
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/common/errors"
|
||||||
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/config"
|
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/config"
|
||||||
"github.com/go-chi/render"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func CreateAuthGuard(cfg *config.Config) func(next http.Handler) http.Handler {
|
func CreateAuthGuard(cfg *config.Config) func(next http.Handler) http.Handler {
|
||||||
|
|
|
@ -5,11 +5,10 @@ import (
|
||||||
"github.com/go-chi/chi/v5/middleware"
|
"github.com/go-chi/chi/v5/middleware"
|
||||||
httpSwagger "github.com/swaggo/http-swagger"
|
httpSwagger "github.com/swaggo/http-swagger"
|
||||||
|
|
||||||
|
_ "code.alt-gnome.ru/aides-infra/aides-repo-api/docs"
|
||||||
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/config"
|
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/config"
|
||||||
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/controllers/taskcontroller"
|
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/controllers/taskcontroller"
|
||||||
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/middlewares"
|
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/middlewares"
|
||||||
|
|
||||||
_ "code.alt-gnome.ru/aides-infra/aides-repo-api/docs"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Router struct {
|
type Router struct {
|
||||||
|
|
|
@ -7,8 +7,9 @@ import (
|
||||||
"path"
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/models"
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
|
||||||
|
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config interface {
|
type Config interface {
|
||||||
|
@ -42,7 +43,14 @@ func createSymlink(target, link string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func runGenbasedir(repoDir, arch, repoName string) {
|
func runGenbasedir(repoDir, arch, repoName string) {
|
||||||
cmd := exec.Command("genbasedir", "--bloat", "--progress", fmt.Sprintf("--topdir=%s", repoDir), arch, repoName)
|
cmd := exec.Command(
|
||||||
|
"genbasedir",
|
||||||
|
"--bloat",
|
||||||
|
"--progress",
|
||||||
|
fmt.Sprintf("--topdir=%s", repoDir),
|
||||||
|
arch,
|
||||||
|
repoName,
|
||||||
|
)
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
err := cmd.Run()
|
err := cmd.Run()
|
||||||
|
@ -114,7 +122,14 @@ func (s *Service) ForceUpdate() {
|
||||||
localFilePath := path.Join(
|
localFilePath := path.Join(
|
||||||
strconv.FormatUint(uint64(el.ID), 10), fileInfo.Name,
|
strconv.FormatUint(uint64(el.ID), 10), fileInfo.Name,
|
||||||
)
|
)
|
||||||
symLink := path.Join(s.config.GetUploadDir(), "future_repo", "Sisyphus", fileInfo.Arch, "RPMS.aides", fileInfo.Name)
|
symLink := path.Join(
|
||||||
|
s.config.GetUploadDir(),
|
||||||
|
"future_repo",
|
||||||
|
"Sisyphus",
|
||||||
|
fileInfo.Arch,
|
||||||
|
"RPMS.aides",
|
||||||
|
fileInfo.Name,
|
||||||
|
)
|
||||||
targetPath := path.Join("../../../../tasks/", localFilePath)
|
targetPath := path.Join("../../../../tasks/", localFilePath)
|
||||||
createSymlink(targetPath, symLink)
|
createSymlink(targetPath, symLink)
|
||||||
|
|
||||||
|
@ -146,7 +161,6 @@ func (s *Service) ForceUpdate() {
|
||||||
if err := os.Rename(bPath, cPath); err != nil {
|
if err := os.Rename(bPath, cPath); err != nil {
|
||||||
}
|
}
|
||||||
} else if !os.IsNotExist(err) {
|
} else if !os.IsNotExist(err) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := os.Rename(aPath, bPath); err != nil {
|
if err := os.Rename(aPath, bPath); err != nil {
|
||||||
|
@ -154,7 +168,6 @@ func (s *Service) ForceUpdate() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := os.RemoveAll(cPath); err != nil {
|
if err := os.RemoveAll(cPath); err != nil {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
os.RemoveAll(path.Join(s.config.GetUploadDir(), "future_repo"))
|
os.RemoveAll(path.Join(s.config.GetUploadDir(), "future_repo"))
|
||||||
|
|
|
@ -5,8 +5,9 @@ import (
|
||||||
"path"
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/models"
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
|
||||||
|
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config interface {
|
type Config interface {
|
||||||
|
|
|
@ -11,8 +11,9 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/models"
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
|
||||||
|
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TaskUploadInput struct {
|
type TaskUploadInput struct {
|
||||||
|
@ -73,7 +74,7 @@ func (s *Service) Upload(input *TaskUploadInput) error {
|
||||||
// Полный путь для файла
|
// Полный путь для файла
|
||||||
filePath := path.Join(taskFolderPath, fileHeader.Filename)
|
filePath := path.Join(taskFolderPath, fileHeader.Filename)
|
||||||
|
|
||||||
//Удаляем файл если такой уже существует
|
// Удаляем файл если такой уже существует
|
||||||
if _, err := os.Stat(filePath); err == nil {
|
if _, err := os.Stat(filePath); err == nil {
|
||||||
err = os.Remove(filePath)
|
err = os.Remove(filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue