From 71f518c6f93455fe1ceb6c82a6a58abcd31f8913 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=97=E5=AD=90?= Date: Thu, 15 May 2025 08:29:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=88=9D=E5=A7=8B=E5=8C=96=E7=BD=91?= =?UTF-8?q?=E7=AB=99=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/biz/website.go | 1 + internal/data/website.go | 2 ++ internal/migration/v1.go | 19 ++++++++----------- pkg/types/website.go | 1 + 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/internal/biz/website.go b/internal/biz/website.go index 8c48f84f..9db94a41 100644 --- a/internal/biz/website.go +++ b/internal/biz/website.go @@ -11,6 +11,7 @@ import ( type Website struct { ID uint `gorm:"primaryKey" json:"id"` Name string `gorm:"not null;default:'';unique" json:"name"` + Type string `gorm:"not null;default:'php'" json:"type"` Status bool `gorm:"not null;default:true" json:"status"` Path string `gorm:"not null;default:''" json:"path"` Https bool `gorm:"not null;default:false" json:"https"` diff --git a/internal/data/website.go b/internal/data/website.go index 795a7235..eb97c460 100644 --- a/internal/data/website.go +++ b/internal/data/website.go @@ -112,6 +112,7 @@ func (r *websiteRepo) Get(id uint) (*types.WebsiteSetting, error) { setting := new(types.WebsiteSetting) setting.ID = website.ID setting.Name = website.Name + setting.Type = website.Type setting.Path = website.Path setting.HTTPS = website.Https setting.PHP = p.GetPHP() @@ -347,6 +348,7 @@ func (r *websiteRepo) Create(req *request.WebsiteCreate) (*biz.Website, error) { // 创建面板网站 w := &biz.Website{ Name: req.Name, + Type: "php", // TODO 支持网站类型 Status: true, Path: req.Path, Https: false, diff --git a/internal/migration/v1.go b/internal/migration/v1.go index aad7ec7f..7d5aebca 100644 --- a/internal/migration/v1.go +++ b/internal/migration/v1.go @@ -94,24 +94,21 @@ func init() { }, }) Migrations = append(Migrations, &gormigrate.Migration{ - ID: "20250514-user-two-fa", + ID: "20250514-user-website", Migrate: func(tx *gorm.DB) error { return tx.AutoMigrate( &biz.User{}, - ) - }, - Rollback: func(tx *gorm.DB) error { - return tx.Migrator().DropColumn(&biz.User{}, "two_fa") - }, - }) - Migrations = append(Migrations, &gormigrate.Migration{ - ID: "20250514-user-token", - Migrate: func(tx *gorm.DB) error { - return tx.AutoMigrate( + &biz.Website{}, &biz.UserToken{}, ) }, Rollback: func(tx *gorm.DB) error { + if err := tx.Migrator().DropColumn(&biz.User{}, "two_fa"); err != nil { + return err + } + if err := tx.Migrator().DropColumn(&biz.Website{}, "type"); err != nil { + return err + } return tx.Migrator().DropTable(&biz.UserToken{}) }, }) diff --git a/pkg/types/website.go b/pkg/types/website.go index 1b242467..b10be8d9 100644 --- a/pkg/types/website.go +++ b/pkg/types/website.go @@ -11,6 +11,7 @@ type WebsiteListen struct { type WebsiteSetting struct { ID uint `json:"id"` Name string `json:"name"` + Type string `json:"type"` Listens []WebsiteListen `form:"listens" json:"listens" validate:"required"` Domains []string `json:"domains"` Path string `json:"path"` // 网站目录