-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
some update to app and add basic vue for front
Signed-off-by: viste <[email protected]>
- Loading branch information
Showing
21 changed files
with
12,498 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,160 @@ | ||
package api | ||
|
||
import ( | ||
"encoding/json" | ||
"github.com/Viste/larets/config" | ||
"github.com/Viste/larets/db" | ||
"github.com/Viste/larets/models" | ||
"github.com/Viste/larets/repositories" | ||
"log" | ||
"net/http" | ||
) | ||
|
||
func RunAPIServer() { | ||
log.Println("Запуск API сервера на порту :8080") | ||
http.HandleFunc("/images", handleImages) | ||
http.HandleFunc("/git", handleGit) | ||
http.HandleFunc("/helm", handleHelm) | ||
http.HandleFunc("/maven", handleMaven) | ||
http.HandleFunc("/rpm", handleRpm) | ||
http.HandleFunc("/deb", handleDeb) | ||
// дополнительные маршруты для работы с CRUD | ||
|
||
if config.Config["ENABLE_DOCKER"] == "true" { | ||
http.HandleFunc("/docker/create", createDockerImage) | ||
http.HandleFunc("/docker/list", listDockerImages) | ||
} | ||
|
||
if config.Config["ENABLE_GIT"] == "true" { | ||
http.HandleFunc("/git/create", createGitRepository) | ||
http.HandleFunc("/git/list", listGitRepositories) | ||
} | ||
|
||
if config.Config["ENABLE_HELM"] == "true" { | ||
http.HandleFunc("/helm/create", createHelmChart) | ||
} | ||
|
||
if config.Config["ENABLE_MAVEN"] == "true" { | ||
http.HandleFunc("/maven/create", createMavenArtifact) | ||
} | ||
|
||
if config.Config["ENABLE_RPM"] == "true" { | ||
http.HandleFunc("/rpm/create", createRpmPackage) | ||
} | ||
|
||
if config.Config["ENABLE_DEB"] == "true" { | ||
http.HandleFunc("/deb/create", createDebPackage) | ||
} | ||
|
||
http.HandleFunc("/files", handleFiles) | ||
|
||
log.Fatal(http.ListenAndServe(":8080", nil)) | ||
} | ||
|
||
func handleImages(w http.ResponseWriter, r *http.Request) { | ||
// Обработка запросов по Docker образам | ||
log.Println("Обработка запроса Docker образов") | ||
w.Write([]byte("Обработка Docker образов")) | ||
func createDockerImage(w http.ResponseWriter, r *http.Request) { | ||
if r.Method != http.MethodPost { | ||
http.Error(w, "Метод не поддерживается", http.StatusMethodNotAllowed) | ||
return | ||
} | ||
|
||
var request struct { | ||
Name string `json:"name"` | ||
Tag string `json:"tag"` | ||
} | ||
if err := json.NewDecoder(r.Body).Decode(&request); err != nil { | ||
http.Error(w, "Ошибка декодирования запроса", http.StatusBadRequest) | ||
return | ||
} | ||
|
||
err := repositories.StoreDockerImage(request.Name, request.Tag) | ||
if err != nil { | ||
http.Error(w, "Ошибка сохранения Docker образа", http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
w.WriteHeader(http.StatusCreated) | ||
w.Write([]byte("Docker образ успешно создан")) | ||
} | ||
|
||
func listDockerImages(w http.ResponseWriter, r *http.Request) { | ||
if r.Method != http.MethodGet { | ||
http.Error(w, "Метод не поддерживается", http.StatusMethodNotAllowed) | ||
return | ||
} | ||
|
||
var images []models.DockerImage | ||
result := db.DB.Find(&images) | ||
if result.Error != nil { | ||
http.Error(w, "Ошибка получения списка Docker образов", http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
w.Header().Set("Content-Type", "application/json") | ||
json.NewEncoder(w).Encode(images) | ||
} | ||
|
||
func createGitRepository(w http.ResponseWriter, r *http.Request) { | ||
if r.Method != http.MethodPost { | ||
http.Error(w, "Метод не поддерживается", http.StatusMethodNotAllowed) | ||
return | ||
} | ||
|
||
var request struct { | ||
Name string `json:"name"` | ||
URL string `json:"url"` | ||
} | ||
if err := json.NewDecoder(r.Body).Decode(&request); err != nil { | ||
http.Error(w, "Ошибка декодирования запроса", http.StatusBadRequest) | ||
return | ||
} | ||
|
||
err := repositories.StoreGitRepository(request.Name, request.URL) | ||
if err != nil { | ||
http.Error(w, "Ошибка сохранения Git репозитория", http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
w.WriteHeader(http.StatusCreated) | ||
w.Write([]byte("Git репозиторий успешно создан")) | ||
} | ||
|
||
func listGitRepositories(w http.ResponseWriter, r *http.Request) { | ||
if r.Method != http.MethodGet { | ||
http.Error(w, "Метод не поддерживается", http.StatusMethodNotAllowed) | ||
return | ||
} | ||
|
||
var repos []models.GitRepository | ||
result := db.DB.Find(&repos) | ||
if result.Error != nil { | ||
http.Error(w, "Ошибка получения списка Git репозиториев", http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
w.Header().Set("Content-Type", "application/json") | ||
json.NewEncoder(w).Encode(repos) | ||
} | ||
|
||
func handleGit(w http.ResponseWriter, r *http.Request) { | ||
// Обработка запросов по Git репозиториям | ||
log.Println("Обработка запроса Git репозиториев") | ||
w.Write([]byte("Обработка Git репозиториев")) | ||
func createHelmChart(w http.ResponseWriter, r *http.Request) { | ||
// Логика для создания Helm чарта | ||
log.Println("Создание Helm чарта") | ||
w.Write([]byte("Helm чарт успешно создан")) | ||
} | ||
|
||
func handleHelm(w http.ResponseWriter, r *http.Request) { | ||
// Обработка запросов по Helm репозиториям | ||
log.Println("Обработка запроса Helm репозиториев") | ||
w.Write([]byte("Обработка Helm репозиториев")) | ||
func createMavenArtifact(w http.ResponseWriter, r *http.Request) { | ||
// Логика для создания Maven артефакта | ||
log.Println("Создание Maven артефакта") | ||
w.Write([]byte("Maven артефакт успешно создан")) | ||
} | ||
|
||
func handleMaven(w http.ResponseWriter, r *http.Request) { | ||
// Обработка запросов по Maven репозиториям | ||
log.Println("Обработка запроса Maven репозиториев") | ||
w.Write([]byte("Обработка Maven репозиториев")) | ||
func createRpmPackage(w http.ResponseWriter, r *http.Request) { | ||
// Логика для создания RPM пакета | ||
log.Println("Создание RPM пакета") | ||
w.Write([]byte("RPM пакет успешно создан")) | ||
} | ||
|
||
func handleRpm(w http.ResponseWriter, r *http.Request) { | ||
// Обработка запросов по RPM репозиториям | ||
log.Println("Обработка запроса RPM репозиториев") | ||
w.Write([]byte("Обработка RPM репозиториев")) | ||
func createDebPackage(w http.ResponseWriter, r *http.Request) { | ||
// Логика для создания DEB пакета | ||
log.Println("Создание DEB пакета") | ||
w.Write([]byte("DEB пакет успешно создан")) | ||
} | ||
|
||
func handleDeb(w http.ResponseWriter, r *http.Request) { | ||
// Обработка запросов по DEB репозиториям | ||
log.Println("Обработка запроса DEB репозиториев") | ||
w.Write([]byte("Обработка DEB репозиториев")) | ||
// handleFiles - новый обработчик для работы с файлами | ||
func handleFiles(w http.ResponseWriter, r *http.Request) { | ||
// Логика для загрузки и хранения файлов | ||
log.Println("Обработка файлов и архивов") | ||
w.Write([]byte("Обработка файлов и архивов")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,20 @@ | ||
package db | ||
|
||
import ( | ||
"database/sql" | ||
_ "github.com/lib/pq" | ||
"gorm.io/driver/postgres" | ||
"gorm.io/gorm" | ||
"log" | ||
) | ||
|
||
func InitDB(connStr string) (*sql.DB, error) { | ||
db, err := sql.Open("postgres", connStr) | ||
if err != nil { | ||
return nil, err | ||
} | ||
var DB *gorm.DB | ||
|
||
// Проверка подключения | ||
if err := db.Ping(); err != nil { | ||
return nil, err | ||
func InitDB(connStr string) error { | ||
db, err := gorm.Open(postgres.Open(connStr), &gorm.Config{}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
log.Println("Подключение к базе данных успешно установлено") | ||
return db, nil | ||
DB = db | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,36 @@ | ||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= | ||
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= | ||
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk= | ||
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= | ||
github.com/jackc/pgx/v5 v5.5.5 h1:amBjrZVmksIdNjxGW/IiIMzxMKZFelXbUoPNb+8sjQw= | ||
github.com/jackc/pgx/v5 v5.5.5/go.mod h1:ez9gk+OAat140fv9ErkZDYFWmXLfV+++K0uAOiwgm1A= | ||
github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk= | ||
github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= | ||
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= | ||
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= | ||
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= | ||
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= | ||
github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg= | ||
github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= | ||
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= | ||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= | ||
github.com/lib/pq v1.10.0 h1:Zx5DJFEYQXio93kgXnQ09fXNiUKsqv4OUEu2UtGcB1E= | ||
github.com/lib/pq v1.10.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= | ||
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= | ||
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= | ||
github.com/lib/pq v1.10.2 h1:AqzbZs4ZoCBp+GtejcpCpcxM3zlSMx29dXbUSeVtJb8= | ||
github.com/lib/pq v1.10.2/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= | ||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= | ||
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k= | ||
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= | ||
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= | ||
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | ||
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= | ||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= | ||
gorm.io/driver/postgres v1.5.9 h1:DkegyItji119OlcaLjqN11kHoUgZ/j13E0jkJZgD6A8= | ||
gorm.io/driver/postgres v1.5.9/go.mod h1:DX3GReXH+3FPWGrrgffdvCk3DQ1dwDPdmbenSkweRGI= | ||
gorm.io/gorm v1.25.10 h1:dQpO+33KalOA+aFYGlK+EfxcI5MbO7EP2yYygwh9h+s= | ||
gorm.io/gorm v1.25.10/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8= | ||
gorm.io/gorm v1.25.12 h1:I0u8i2hWQItBq1WfE0o2+WuL9+8L21K9e2HHSTE/0f8= | ||
gorm.io/gorm v1.25.12/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,26 @@ | ||
package repositories | ||
|
||
import ( | ||
"github.com/Viste/larets/db" | ||
"github.com/Viste/larets/models" | ||
"log" | ||
) | ||
|
||
func StoreDockerImage(imageName string, tag string) { | ||
// Здесь будет логика для сохранения Docker образа в файловую систему и сохранения метаданных в базу данных | ||
func StoreDockerImage(imageName string, tag string) error { | ||
dockerImage := models.DockerImage{Name: imageName, Tag: tag} | ||
result := db.DB.Create(&dockerImage) | ||
if result.Error != nil { | ||
return result.Error | ||
} | ||
log.Printf("Сохраняем образ: %s с тэгом: %s", imageName, tag) | ||
return nil | ||
} | ||
|
||
func ProxyDockerRepository(repoURL string) { | ||
// Логика проксирования запросов к удаленным Docker репозиториям | ||
log.Printf("Проксируем Docker репозиторий: %s", repoURL) | ||
} | ||
|
||
func ProxyGitRepository(repoURL string) { | ||
// Логика проксирования запросов к удаленным Git репозиториям и сохранения копий | ||
log.Printf("Проксируем Git репозиторий: %s", repoURL) | ||
func InitDockerRepository() { | ||
log.Println("Инициализация Docker репозитория") | ||
} |
Oops, something went wrong.