package api_management import ( "adm-management/errors" "adm-management/model" "adm-management/parser" 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" ) func AllAPI(ctx context.Context, req *v1.AllAPIRequest) (reply *v1.AllAPIReply, err error) { reply = &v1.AllAPIReply{} // 捕获各个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")) } } }() if req.AllApi == "" { pagination := model.NewPagination(0, 100000, 0).GetLimitOffset() list, err := model.NewAPIList().List(database.DB().Where("api_no is NOT NULL").Order("api_no"), pagination) if err != nil && err != gorm.ErrRecordNotFound { return reply, errors.SystemError } if err == gorm.ErrRecordNotFound { return reply, nil } reply.List = make([]string, 0, len(list)) for _, v := range list { reply.Host = parser.Conf.Rpc.ADMManagement.Host reply.List = append(reply.List, v.ApiNo) } } else { pagination := model.NewPagination(0, 100000, 0).GetLimitOffset() list, err := model.NewAPIList().List(database.DB().Where("api_no like ?", "%"+req.AllApi+"%").Order("api_no"), pagination) if err != nil && err != gorm.ErrRecordNotFound { return reply, errors.SystemError } if err == gorm.ErrRecordNotFound { return reply, nil } reply.List = make([]string, 0, len(list)) for _, v := range list { reply.Host = parser.Conf.Rpc.ADMManagement.Host reply.List = append(reply.List, v.ApiNo) } } return reply, nil } func AllKey(ctx context.Context, req *v1.AllKeyRequest) (reply *v1.AllKeyReply, err error) { reply = &v1.AllKeyReply{} // 捕获各个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")) } } }() if req.AllKey == "" { pagination := model.NewPagination(0, 100000, 0).GetLimitOffset() list, err := model.NewKeyList().List(database.DB().Where("`key` is NOT NULL"), pagination) if err != nil && err != gorm.ErrRecordNotFound { return reply, errors.SystemError } if err == gorm.ErrRecordNotFound { return reply, nil } reply.List = make([]string, 0, len(list)) for _, v := range list { reply.List = append(reply.List, v.Key) } } return reply, nil }