mirror of https://github.com/veypi/OneAuth.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
545 B
Go
27 lines
545 B
Go
package role
|
|
|
|
import (
|
|
"github.com/vyes/vigo"
|
|
"github.com/veypi/OneAuth/cfg"
|
|
"github.com/veypi/OneAuth/models"
|
|
)
|
|
|
|
var _ = Router.Get("/:role_id", getRole)
|
|
|
|
func getRole(x *vigo.X) (any, error) {
|
|
// 获取角色 ID
|
|
roleID := x.Params.Get("role_id")
|
|
if roleID == "" {
|
|
return nil, vigo.NewError("role_id is required").WithCode(400)
|
|
}
|
|
|
|
// 查询数据库
|
|
role := &models.Role{}
|
|
err := cfg.DB().Where("id = ?", roleID).First(role).Error
|
|
if err != nil {
|
|
return nil, vigo.NewError("role not found").WithCode(404)
|
|
}
|
|
|
|
return role, nil
|
|
}
|