mirror of
https://github.com/xinliangnote/go-gin-api.git
synced 2024-04-21 12:31:46 +00:00
- 将 middleware 命名为 interceptor - 将 deploy 命名为 deployments - 移除 pkg/errno - 使用 proposal 目录 - 优化代码
38 lines
1.0 KiB
Go
38 lines
1.0 KiB
Go
package authorized
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"encoding/hex"
|
|
"io"
|
|
|
|
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
|
"github.com/xinliangnote/go-gin-api/internal/repository/mysql/authorized"
|
|
)
|
|
|
|
type CreateAuthorizedData struct {
|
|
BusinessKey string `json:"business_key"` // 调用方key
|
|
BusinessDeveloper string `json:"business_developer"` // 调用方对接人
|
|
Remark string `json:"remark"` // 备注
|
|
}
|
|
|
|
func (s *service) Create(ctx core.Context, authorizedData *CreateAuthorizedData) (id int32, err error) {
|
|
buf := make([]byte, 10)
|
|
io.ReadFull(rand.Reader, buf)
|
|
secret := hex.EncodeToString(buf)
|
|
|
|
model := authorized.NewModel()
|
|
model.BusinessKey = authorizedData.BusinessKey
|
|
model.BusinessSecret = secret
|
|
model.BusinessDeveloper = authorizedData.BusinessDeveloper
|
|
model.Remark = authorizedData.Remark
|
|
model.CreatedUser = ctx.SessionUserInfo().UserName
|
|
model.IsUsed = 1
|
|
model.IsDeleted = -1
|
|
|
|
id, err = model.Create(s.db.GetDbW().WithContext(ctx.RequestContext()))
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return
|
|
}
|