1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- package api_management
- import (
- "adm-management/errors"
- v1 "adm-management/pb/v1"
- "context"
- "encoding/json"
- "fmt"
- "git.getensh.com/common/gopkgsv2/database"
- "git.getensh.com/common/gopkgsv2/logger"
- "go.uber.org/zap"
- "google.golang.org/grpc/status"
- "gorm.io/gorm"
- )
- type KVList struct {
- Key string `json:"key"`
- Value string `json:"value"`
- Desc string `json:"desc"`
- }
- func UseAPI(ctx context.Context, req *v1.UseAPIRequest) (reply *v1.UseAPIReply, err error) {
- defer func() {
- if r := recover(); r != nil {
- err = fmt.Errorf("%+v", r)
- e := &status.Status{}
- if er := json.Unmarshal([]byte(err.Error()), e); er != nil {
- logger.Error("err",
- zap.String("system_err", err.Error()),
- zap.Stack("stacktrace"))
- }
- }
- }()
- reply = &v1.UseAPIReply{}
- if req.ApiId != 0 {
- db := database.DB()
- var api string
- err = db.Raw("SELECT request FROM t_adm_api_management where id = ?", req.ApiId).Find(&api).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return reply, nil
- }
- return reply, errors.SystemError
- }
- var ReqMap = make(map[string]string)
- if api[2:6] == "list" {
- s := api[9 : len(api)-2]
- _ = json.Unmarshal([]byte(s), &ReqMap)
- for a, b := range ReqMap {
- reply.Request = append(reply.Request, &v1.CheckAPI{
- Key: a,
- Value: "",
- Desc: b,
- })
- }
- return reply, nil
- }
- _ = json.Unmarshal([]byte(api), &ReqMap)
- for k, v := range ReqMap {
- reply.Request = append(reply.Request, &v1.CheckAPI{
- Key: k,
- Value: "",
- Desc: v,
- })
- }
- return reply, nil
- }
- return reply, nil
- }
|