alist/model/setting.go

40 lines
790 B
Go
Raw Normal View History

2021-10-26 14:28:37 +00:00
package model
2021-10-27 10:59:03 +00:00
import (
"github.com/Xhofe/alist/conf"
)
const (
PUBLIC = iota
PRIVATE
CONST
)
2021-10-26 14:28:37 +00:00
type SettingItem struct {
Key string `json:"key" gorm:"primaryKey" validate:"required"`
Value string `json:"value"`
Description string `json:"description"`
Type int `json:"type"`
}
func SaveSettings(items []SettingItem) error {
return conf.DB.Save(items).Error
}
func GetSettingByType(t int) (*[]SettingItem, error) {
var items []SettingItem
if err := conf.DB.Where("type = ?", t).Find(&items).Error; err != nil {
return nil, err
}
return &items, nil
}
2021-10-27 10:59:03 +00:00
func GetSettingByKey(key string) (*SettingItem, error) {
var items SettingItem
if err := conf.DB.Where("key = ?", key).First(&items).Error; err != nil {
return nil, err
}
return &items, nil
}