123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- 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
- }
|