Go(Gin) + React(Vite + shadcn/ui + Tailwind) 前后端分离,全中文 UI - 集群管理:Kubeconfig / Token 双接入,kubectl + helm 部署 - 主机管理:SSH 密钥 / 密码双认证,CPU/内存/磁盘使用率监控,SSH 错误中文友好提示 - 存储配置、部署管理、系统设置 - Docker 镜像内置 kubectl + helm,开箱即用 - run.sh 一键启停(start/stop/restart/status) Co-Authored-By: Claude <noreply@anthropic.com>
111 lines
2.8 KiB
Go
111 lines
2.8 KiB
Go
package controllers
|
|
|
|
import (
|
|
"lokideploy/models"
|
|
"lokideploy/services"
|
|
"lokideploy/utils"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type StorageController struct {
|
|
service *services.StorageService
|
|
}
|
|
|
|
func NewStorageController() *StorageController {
|
|
return &StorageController{service: services.NewStorageService()}
|
|
}
|
|
|
|
type CreateStorageRequest struct {
|
|
Name string `json:"name" binding:"required"`
|
|
StorageType string `json:"storageType" binding:"required,oneof=s3 oss minio rustfs"`
|
|
Endpoint string `json:"endpoint"`
|
|
Bucket string `json:"bucket" binding:"required"`
|
|
Region string `json:"region"`
|
|
AccessKey string `json:"accessKey"`
|
|
SecretKey string `json:"secretKey"`
|
|
PathPrefix string `json:"pathPrefix"`
|
|
Insecure bool `json:"insecure"`
|
|
IsDefault bool `json:"isDefault"`
|
|
}
|
|
|
|
func (ctrl *StorageController) Create(c *gin.Context) {
|
|
var req CreateStorageRequest
|
|
if !utils.BindAndValidate(c, &req) {
|
|
return
|
|
}
|
|
storage, err := ctrl.service.Create(req.Name, req.StorageType, req.Endpoint, req.Bucket,
|
|
req.Region, req.AccessKey, req.SecretKey, req.PathPrefix, req.Insecure, req.IsDefault)
|
|
if err != nil {
|
|
utils.Error(c, 400, err.Error())
|
|
return
|
|
}
|
|
utils.Success(c, models.SanitizedJSON(storage))
|
|
}
|
|
|
|
func (ctrl *StorageController) Get(c *gin.Context) {
|
|
id, err := utils.IntParam(c, "id")
|
|
if err != nil {
|
|
utils.BadRequest(c, "ID 无效")
|
|
return
|
|
}
|
|
storage, err := ctrl.service.Get(uint(id))
|
|
if err != nil {
|
|
utils.NotFound(c, "存储配置不存在")
|
|
return
|
|
}
|
|
utils.Success(c, models.SanitizedJSON(storage))
|
|
}
|
|
|
|
func (ctrl *StorageController) List(c *gin.Context) {
|
|
page, pageSize := utils.Pagination(c)
|
|
storages, total, err := ctrl.service.List(page, pageSize)
|
|
if err != nil {
|
|
utils.Error(c, 500, err.Error())
|
|
return
|
|
}
|
|
utils.Success(c, utils.PageData{
|
|
List: models.SanitizedJSON(storages),
|
|
Total: total, Page: page, PageSize: pageSize,
|
|
})
|
|
}
|
|
|
|
func (ctrl *StorageController) Update(c *gin.Context) {
|
|
id, err := utils.IntParam(c, "id")
|
|
if err != nil {
|
|
utils.BadRequest(c, "ID 无效")
|
|
return
|
|
}
|
|
var updates map[string]interface{}
|
|
if !utils.BindAndValidate(c, &updates) {
|
|
return
|
|
}
|
|
if err := ctrl.service.Update(uint(id), updates); err != nil {
|
|
utils.Error(c, 400, err.Error())
|
|
return
|
|
}
|
|
utils.Success(c, gin.H{"message": "updated"})
|
|
}
|
|
|
|
func (ctrl *StorageController) Delete(c *gin.Context) {
|
|
id, err := utils.IntParam(c, "id")
|
|
if err != nil {
|
|
utils.BadRequest(c, "ID 无效")
|
|
return
|
|
}
|
|
if err := ctrl.service.Delete(uint(id)); err != nil {
|
|
utils.Error(c, 400, err.Error())
|
|
return
|
|
}
|
|
utils.Success(c, gin.H{"message": "deleted"})
|
|
}
|
|
|
|
func (ctrl *StorageController) GetDefault(c *gin.Context) {
|
|
storage, err := ctrl.service.GetDefault()
|
|
if err != nil {
|
|
utils.NotFound(c, "未设置默认存储配置")
|
|
return
|
|
}
|
|
utils.Success(c, models.SanitizedJSON(storage))
|
|
}
|