优化
This commit is contained in:
+23
-2
@@ -10,11 +10,11 @@ import (
|
||||
)
|
||||
|
||||
type APIService struct {
|
||||
uc *biz.AccessUsecase
|
||||
uc *biz.APIUsecase
|
||||
runtime *conf.Runtime
|
||||
}
|
||||
|
||||
func NewAPIService(uc *biz.AccessUsecase, runtime *conf.Runtime) *APIService {
|
||||
func NewAPIService(uc *biz.APIUsecase, runtime *conf.Runtime) *APIService {
|
||||
return &APIService{uc: uc, runtime: runtime}
|
||||
}
|
||||
|
||||
@@ -63,6 +63,27 @@ func (s *APIService) AllAPI(ctx context.Context, strict bool) ([]*dto.APIRespons
|
||||
return apiResponses(items), nil
|
||||
}
|
||||
|
||||
func (s *APIService) Groups(ctx context.Context) ([]string, map[string]string, error) {
|
||||
items, err := s.AllAPI(ctx, false)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
seen := make(map[string]bool)
|
||||
groups := make([]string, 0)
|
||||
groupAPIMap := make(map[string]string)
|
||||
for _, item := range items {
|
||||
if !seen[item.APIGroup] {
|
||||
seen[item.APIGroup] = true
|
||||
groups = append(groups, item.APIGroup)
|
||||
}
|
||||
parts := strings.Split(item.Path, "/")
|
||||
if len(parts) > 1 {
|
||||
groupAPIMap[parts[1]] = item.APIGroup
|
||||
}
|
||||
}
|
||||
return groups, groupAPIMap, nil
|
||||
}
|
||||
|
||||
func (s *APIService) CreateAPIRequest(ctx context.Context, req *dto.APIRequest) (*dto.APIResponse, error) {
|
||||
value := apiDomain(req)
|
||||
if err := s.uc.CreateAPI(ctx, value); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user