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 目录 - 优化代码
32 lines
1.0 KiB
Go
32 lines
1.0 KiB
Go
package authorized
|
|
|
|
import (
|
|
"github.com/xinliangnote/go-gin-api/configs"
|
|
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
|
"github.com/xinliangnote/go-gin-api/internal/repository/mysql/authorized_api"
|
|
"github.com/xinliangnote/go-gin-api/internal/repository/redis"
|
|
)
|
|
|
|
type CreateAuthorizedAPIData struct {
|
|
BusinessKey string `json:"business_key"` // 调用方key
|
|
Method string `json:"method"` // 请求方法
|
|
API string `json:"api"` // 请求地址
|
|
}
|
|
|
|
func (s *service) CreateAPI(ctx core.Context, authorizedAPIData *CreateAuthorizedAPIData) (id int32, err error) {
|
|
model := authorized_api.NewModel()
|
|
model.BusinessKey = authorizedAPIData.BusinessKey
|
|
model.Method = authorizedAPIData.Method
|
|
model.Api = authorizedAPIData.API
|
|
model.CreatedUser = ctx.SessionUserInfo().UserName
|
|
model.IsDeleted = -1
|
|
|
|
id, err = model.Create(s.db.GetDbW().WithContext(ctx.RequestContext()))
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
s.cache.Del(configs.RedisKeyPrefixSignature+authorizedAPIData.BusinessKey, redis.WithTrace(ctx.Trace()))
|
|
return
|
|
}
|