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"
|
||||
"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/controllers/taskcontroller"
|
||||
"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/reposervice"
|
||||
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/services/taskservice"
|
||||
"gorm.io/driver/postgres"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
|
@ -29,7 +30,14 @@ type App struct {
|
|||
}
|
||||
|
||||
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{})
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ type Config struct {
|
|||
Token string `env:"TOKEN"`
|
||||
UploadDir string `env:"UPLOAD_DIR" envDefault:"./uploads"`
|
||||
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"`
|
||||
DBPort string `env:"DB_PORT" envDefault:"5432"`
|
||||
|
|
|
@ -4,9 +4,10 @@ import (
|
|||
"encoding/json"
|
||||
"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/models"
|
||||
"github.com/go-chi/render"
|
||||
)
|
||||
|
||||
type CreateTaskDTO struct {
|
||||
|
|
|
@ -4,10 +4,11 @@ import (
|
|||
"fmt"
|
||||
"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/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 {
|
||||
|
|
|
@ -3,9 +3,10 @@ package middlewares
|
|||
import (
|
||||
"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/config"
|
||||
"github.com/go-chi/render"
|
||||
)
|
||||
|
||||
func CreateAuthGuard(cfg *config.Config) func(next http.Handler) http.Handler {
|
||||
|
|
|
@ -5,11 +5,10 @@ import (
|
|||
"github.com/go-chi/chi/v5/middleware"
|
||||
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/controllers/taskcontroller"
|
||||
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/middlewares"
|
||||
|
||||
_ "code.alt-gnome.ru/aides-infra/aides-repo-api/docs"
|
||||
)
|
||||
|
||||
type Router struct {
|
||||
|
|
|
@ -7,8 +7,9 @@ import (
|
|||
"path"
|
||||
"strconv"
|
||||
|
||||
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/models"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/models"
|
||||
)
|
||||
|
||||
type Config interface {
|
||||
|
@ -42,7 +43,14 @@ func createSymlink(target, link string) error {
|
|||
}
|
||||
|
||||
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.Stderr = os.Stderr
|
||||
err := cmd.Run()
|
||||
|
@ -114,7 +122,14 @@ func (s *Service) ForceUpdate() {
|
|||
localFilePath := path.Join(
|
||||
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)
|
||||
createSymlink(targetPath, symLink)
|
||||
|
||||
|
@ -146,7 +161,6 @@ func (s *Service) ForceUpdate() {
|
|||
if err := os.Rename(bPath, cPath); err != nil {
|
||||
}
|
||||
} else if !os.IsNotExist(err) {
|
||||
|
||||
}
|
||||
|
||||
if err := os.Rename(aPath, bPath); err != nil {
|
||||
|
@ -154,7 +168,6 @@ func (s *Service) ForceUpdate() {
|
|||
}
|
||||
|
||||
if err := os.RemoveAll(cPath); err != nil {
|
||||
|
||||
}
|
||||
|
||||
os.RemoveAll(path.Join(s.config.GetUploadDir(), "future_repo"))
|
||||
|
|
|
@ -5,8 +5,9 @@ import (
|
|||
"path"
|
||||
"strconv"
|
||||
|
||||
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/models"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/models"
|
||||
)
|
||||
|
||||
type Config interface {
|
||||
|
|
|
@ -11,8 +11,9 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
|
||||
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/models"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/models"
|
||||
)
|
||||
|
||||
type TaskUploadInput struct {
|
||||
|
@ -73,7 +74,7 @@ func (s *Service) Upload(input *TaskUploadInput) error {
|
|||
// Полный путь для файла
|
||||
filePath := path.Join(taskFolderPath, fileHeader.Filename)
|
||||
|
||||
//Удаляем файл если такой уже существует
|
||||
// Удаляем файл если такой уже существует
|
||||
if _, err := os.Stat(filePath); err == nil {
|
||||
err = os.Remove(filePath)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in a new issue