mirror of
https://github.com/bjdgyc/anylink.git
synced 2025-08-08 15:56:43 +08:00
修改为sql数据库
This commit is contained in:
@@ -1,35 +1,19 @@
|
||||
package dbdata
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
const (
|
||||
SettingBucket = "SettingBucket"
|
||||
Installed = "Installed"
|
||||
InstallName = "Install"
|
||||
InstallData = "OK"
|
||||
)
|
||||
|
||||
func StructName(data interface{}) string {
|
||||
ref := reflect.ValueOf(data)
|
||||
s := &ref
|
||||
if s.Kind() == reflect.Ptr {
|
||||
e := s.Elem()
|
||||
s = &e
|
||||
}
|
||||
name := s.Type().Name()
|
||||
return name
|
||||
}
|
||||
|
||||
func SettingSet(data interface{}) error {
|
||||
key := StructName(data)
|
||||
err := Set(SettingBucket, key, data)
|
||||
return err
|
||||
}
|
||||
|
||||
func SettingGet(data interface{}) error {
|
||||
key := StructName(data)
|
||||
err := Get(SettingBucket, key, data)
|
||||
return err
|
||||
type Setting struct {
|
||||
Id int `json:"id" xorm:"pk autoincr not null"`
|
||||
Name string `json:"name" xorm:"not null unique"`
|
||||
Data string `json:"data" xorm:"Text"`
|
||||
}
|
||||
|
||||
type SettingSmtp struct {
|
||||
@@ -46,3 +30,41 @@ type SettingOther struct {
|
||||
Banner string `json:"banner"`
|
||||
AccountMail string `json:"account_mail"`
|
||||
}
|
||||
|
||||
func StructName(data interface{}) string {
|
||||
ref := reflect.ValueOf(data)
|
||||
s := &ref
|
||||
if s.Kind() == reflect.Ptr {
|
||||
e := s.Elem()
|
||||
s = &e
|
||||
}
|
||||
name := s.Type().Name()
|
||||
return name
|
||||
}
|
||||
|
||||
func SettingAdd(data interface{}) error {
|
||||
name := StructName(data)
|
||||
v, _ := json.Marshal(data)
|
||||
s := Setting{Name: name, Data: string(v)}
|
||||
err := Add(&s)
|
||||
return err
|
||||
}
|
||||
|
||||
func SettingSet(data interface{}) error {
|
||||
name := StructName(data)
|
||||
v, _ := json.Marshal(data)
|
||||
s := Setting{Data: string(v)}
|
||||
err := Update("name", name, &s)
|
||||
return err
|
||||
}
|
||||
|
||||
func SettingGet(data interface{}) error {
|
||||
name := StructName(data)
|
||||
s := Setting{Name: name}
|
||||
err := One("name", name, &s)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = json.Unmarshal([]byte(s.Data), data)
|
||||
return err
|
||||
}
|
||||
|
Reference in New Issue
Block a user