-
Notifications
You must be signed in to change notification settings - Fork 0
/
service_createapi.go
31 lines (26 loc) · 1.03 KB
/
service_createapi.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package authorized_service
import (
"github.com/skyzhouzj/xhframwork/configs"
"github.com/skyzhouzj/xhframwork/internal/api/repository/db_repo/authorized_api_repo"
"github.com/skyzhouzj/xhframwork/internal/pkg/cache"
"github.com/skyzhouzj/xhframwork/internal/pkg/core"
)
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_repo.NewModel()
model.BusinessKey = authorizedAPIData.BusinessKey
model.Method = authorizedAPIData.Method
model.Api = authorizedAPIData.API
model.CreatedUser = ctx.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, cache.WithTrace(ctx.Trace()))
return
}