update
This commit is contained in:
41
pkg/opencatd/db/keydb.go
Normal file
41
pkg/opencatd/db/keydb.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package db
|
||||
|
||||
import "gorm.io/gorm"
|
||||
|
||||
type Key struct {
|
||||
gorm.Model
|
||||
ApiKey string
|
||||
UserId string
|
||||
}
|
||||
|
||||
// 添加记录
|
||||
func AddKey(apiKey string, userId string) error {
|
||||
key := Key{
|
||||
ApiKey: apiKey,
|
||||
UserId: userId,
|
||||
}
|
||||
if err := db.Create(&key).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// 删除记录
|
||||
func DeleteKey(id uint) error {
|
||||
if err := db.Delete(&Key{}, id).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// 更新记录
|
||||
func UpdateKey(id uint, apiKey string, userId string) error {
|
||||
key := Key{
|
||||
ApiKey: apiKey,
|
||||
UserId: userId,
|
||||
}
|
||||
if err := db.Model(&Key{}).Where("id = ?", id).Updates(key).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user