123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- package api_management
- import (
- "adm-management/errors"
- v1 "adm-management/pb/v1"
- "context"
- "encoding/json"
- "fmt"
- "gorm.io/gorm"
- "git.getensh.com/common/gopkgsv2/database"
- "git.getensh.com/common/gopkgsv2/logger"
- "go.uber.org/zap"
- "google.golang.org/grpc/status"
- )
- func DeleteAPI(ctx context.Context, req *v1.DeleteAPIRequest) (reply *v1.DeleteAPIReply, err error) {
- reply = &v1.DeleteAPIReply{}
- // 捕获各个task中的异常并返回给调用者
- 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"))
- }
- }
- }()
- db := database.DB()
- err = db.Exec("DELETE FROM t_adm_api_management WHERE id = ?", req.ApiId).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return reply, nil
- }
- return reply, errors.SystemError
- }
- return reply, nil
- }
- func DeleteKey(ctx context.Context, req *v1.DeleteKeyRequest) (reply *v1.DeleteKeyReply, err error) {
- reply = &v1.DeleteKeyReply{}
- // 捕获各个task中的异常并返回给调用者
- 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"))
- }
- }
- }()
- db := database.DB()
- err = db.Exec("DELETE FROM t_adm_key_management WHERE `key` = ?", req.Key).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return reply, nil
- }
- return reply, errors.SystemError
- }
- return reply, nil
- }
|