This commit is contained in:
C菌
2023-03-29 02:40:21 +08:00
parent 2ba63e226d
commit 8985c03ac9
5 changed files with 177 additions and 44 deletions

41
pkg/opencatd/db/keydb.go Normal file
View 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
}