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.
38 lines
687 B
Go
38 lines
687 B
Go
package role
|
|
|
|
import (
|
|
"github.com/veypi/OneAuth/cfg"
|
|
"github.com/veypi/OneAuth/models"
|
|
"github.com/veypi/OneBD/rest"
|
|
)
|
|
|
|
var _ = Router.Post("/", createRole)
|
|
|
|
type createOpts struct {
|
|
AppID string `parse:"path"` // 应用 ID
|
|
Name string `json:"name"` // 角色名称
|
|
Des string `json:"des"` // 角色描述
|
|
}
|
|
|
|
func createRole(x *rest.X) (any, error) {
|
|
// 解析参数
|
|
opts := &createOpts{}
|
|
if err := x.Parse(opts); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// 创建角色
|
|
role := &models.Role{
|
|
AppID: opts.AppID,
|
|
Name: opts.Name,
|
|
Des: opts.Des,
|
|
}
|
|
|
|
// 保存到数据库
|
|
if err := cfg.DB().Create(role).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return role, nil
|
|
}
|