mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 10:25:52 +02:00
49 lines
874 B
Go
49 lines
874 B
Go
package model
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"log"
|
|
"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 := ioutil.ReadFile(path)
|
|
if err != nil {
|
|
log.Println(err)
|
|
}
|
|
|
|
config := ConfigBackup{Name: filepath.Base(path), FilePath: path, Content: string(content)}
|
|
result := db.Create(&config)
|
|
if result.Error != nil {
|
|
log.Println(result.Error)
|
|
}
|
|
}
|