mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 18:35:51 +02:00
refactor: project directory structure
This commit is contained in:
parent
c1193a5b8c
commit
e5a5889931
367 changed files with 710 additions and 756 deletions
49
model/config_backup.go
Normal file
49
model/config_backup.go
Normal file
|
@ -0,0 +1,49 @@
|
|||
package model
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/internal/logger"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
type ConfigBackup struct {
|
||||
Model
|
||||
|
||||
Name string `json:"name"`
|
||||
FilePath string `json:"file_path"`
|
||||
Content string `json:"content" gorm:"type:text"`
|
||||
}
|
||||
|
||||
type ConfigBackupListItem struct {
|
||||
Model
|
||||
|
||||
Name string `json:"name"`
|
||||
FilePath string `json:"file_path"`
|
||||
}
|
||||
|
||||
func GetBackupList(path string) (configs []ConfigBackupListItem) {
|
||||
db.Model(&ConfigBackup{}).
|
||||
Where(&ConfigBackup{FilePath: path}).
|
||||
Find(&configs)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func GetBackup(id int) (config ConfigBackup) {
|
||||
db.First(&config, id)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func CreateBackup(path string) {
|
||||
content, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
}
|
||||
|
||||
config := ConfigBackup{Name: filepath.Base(path), FilePath: path, Content: string(content)}
|
||||
result := db.Create(&config)
|
||||
if result.Error != nil {
|
||||
logger.Error(result.Error)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue