feat: 添加鉴权组件

This commit is contained in:
lixiangwuxian
2024-10-20 01:24:45 +08:00
parent 0efdd71c8a
commit b1fa836304
4 changed files with 72 additions and 2 deletions

24
auth/service.go Normal file
View File

@@ -0,0 +1,24 @@
package auth
import (
"database/sql"
"git.lxtend.com/qqbot/constants"
"git.lxtend.com/qqbot/sqlite3"
)
func getAuth(qqID int64) (auth Auth, err error) {
tx, err := sqlite3.GetTran()
if err != nil {
return Auth{}, err
}
defer tx.Rollback()
err = tx.Get(&auth, "SELECT * FROM auth WHERE qqid = ?", qqID)
if err == sql.ErrNoRows {
_, err = tx.Exec("INSERT INTO auth(qqid, role) VALUES(?, ?)", qqID, constants.LEVEL_USER)
}
if err != nil {
return Auth{}, err
}
return auth, nil
}