mirror of
https://github.com/APIParkLab/APIPark.git
synced 2026-06-14 20:41:15 +08:00
路由、权限相关接口完成
This commit is contained in:
@@ -1,33 +1,33 @@
|
||||
package api
|
||||
package router
|
||||
|
||||
import (
|
||||
"github.com/APIParkLab/APIPark/module/api"
|
||||
api_doc "github.com/APIParkLab/APIPark/module/api-doc"
|
||||
api_doc_dto "github.com/APIParkLab/APIPark/module/api-doc/dto"
|
||||
api_dto "github.com/APIParkLab/APIPark/module/api/dto"
|
||||
"github.com/APIParkLab/APIPark/module/router"
|
||||
router_dto "github.com/APIParkLab/APIPark/module/router/dto"
|
||||
"github.com/gin-gonic/gin"
|
||||
"io"
|
||||
)
|
||||
|
||||
var _ IAPIController = (*imlAPIController)(nil)
|
||||
var _ IRouterController = (*imlAPIController)(nil)
|
||||
|
||||
type imlAPIController struct {
|
||||
module api.IApiModule `autowired:""`
|
||||
module router.IRouterModule `autowired:""`
|
||||
}
|
||||
|
||||
func (i *imlAPIController) Detail(ctx *gin.Context, serviceId string, apiId string) (*api_dto.ApiDetail, error) {
|
||||
func (i *imlAPIController) Detail(ctx *gin.Context, serviceId string, apiId string) (*router_dto.Detail, error) {
|
||||
return i.module.Detail(ctx, serviceId, apiId)
|
||||
}
|
||||
|
||||
func (i *imlAPIController) Search(ctx *gin.Context, keyword string, serviceId string) ([]*api_dto.ApiItem, error) {
|
||||
func (i *imlAPIController) Search(ctx *gin.Context, keyword string, serviceId string) ([]*router_dto.Item, error) {
|
||||
return i.module.Search(ctx, keyword, serviceId)
|
||||
}
|
||||
|
||||
func (i *imlAPIController) Create(ctx *gin.Context, serviceId string, dto *api_dto.CreateApi) (*api_dto.ApiSimpleDetail, error) {
|
||||
func (i *imlAPIController) Create(ctx *gin.Context, serviceId string, dto *router_dto.Create) (*router_dto.SimpleDetail, error) {
|
||||
return i.module.Create(ctx, serviceId, dto)
|
||||
}
|
||||
|
||||
func (i *imlAPIController) Edit(ctx *gin.Context, serviceId string, apiId string, dto *api_dto.EditApi) (*api_dto.ApiSimpleDetail, error) {
|
||||
func (i *imlAPIController) Edit(ctx *gin.Context, serviceId string, apiId string, dto *router_dto.Edit) (*router_dto.SimpleDetail, error) {
|
||||
return i.module.Edit(ctx, serviceId, apiId, dto)
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package api
|
||||
package router
|
||||
|
||||
import (
|
||||
api_doc_dto "github.com/APIParkLab/APIPark/module/api-doc/dto"
|
||||
@@ -8,18 +8,18 @@ import (
|
||||
|
||||
"github.com/eolinker/go-common/autowire"
|
||||
|
||||
api_dto "github.com/APIParkLab/APIPark/module/api/dto"
|
||||
router_dto "github.com/APIParkLab/APIPark/module/router/dto"
|
||||
)
|
||||
|
||||
type IAPIController interface {
|
||||
type IRouterController interface {
|
||||
// Detail 获取API详情
|
||||
Detail(ctx *gin.Context, serviceId string, apiId string) (*api_dto.ApiDetail, error)
|
||||
Detail(ctx *gin.Context, serviceId string, apiId string) (*router_dto.Detail, error)
|
||||
// Search 获取API列表
|
||||
Search(ctx *gin.Context, keyword string, serviceId string) ([]*api_dto.ApiItem, error)
|
||||
Search(ctx *gin.Context, keyword string, serviceId string) ([]*router_dto.Item, error)
|
||||
// Create 创建API
|
||||
Create(ctx *gin.Context, serviceId string, dto *api_dto.CreateApi) (*api_dto.ApiSimpleDetail, error)
|
||||
Create(ctx *gin.Context, serviceId string, dto *router_dto.Create) (*router_dto.SimpleDetail, error)
|
||||
// Edit 编辑API
|
||||
Edit(ctx *gin.Context, serviceId string, apiId string, dto *api_dto.EditApi) (*api_dto.ApiSimpleDetail, error)
|
||||
Edit(ctx *gin.Context, serviceId string, apiId string, dto *router_dto.Edit) (*router_dto.SimpleDetail, error)
|
||||
// Delete 删除API
|
||||
Delete(ctx *gin.Context, serviceId string, apiId string) error
|
||||
// Prefix 获取API前缀
|
||||
@@ -36,7 +36,7 @@ type IAPIDocController interface {
|
||||
}
|
||||
|
||||
func init() {
|
||||
autowire.Auto[IAPIController](func() reflect.Value {
|
||||
autowire.Auto[IRouterController](func() reflect.Value {
|
||||
return reflect.ValueOf(new(imlAPIController))
|
||||
})
|
||||
|
||||
@@ -5,9 +5,9 @@ import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/APIParkLab/APIPark/module/api"
|
||||
application_authorization "github.com/APIParkLab/APIPark/module/application-authorization"
|
||||
"github.com/APIParkLab/APIPark/module/catalogue"
|
||||
"github.com/APIParkLab/APIPark/module/router"
|
||||
"github.com/APIParkLab/APIPark/module/service"
|
||||
"github.com/APIParkLab/APIPark/module/subscribe"
|
||||
"github.com/APIParkLab/APIPark/module/team"
|
||||
@@ -23,7 +23,7 @@ type imlExportConfigController struct {
|
||||
teamModule team.ITeamExportModule `autowired:""`
|
||||
serviceModule service.IExportServiceModule `autowired:""`
|
||||
appModule service.IExportAppModule `autowired:""`
|
||||
apiModule api.IExportApiModule `autowired:""`
|
||||
routerModule router.IExportRouterModule `autowired:""`
|
||||
upstreamModule upstream.IExportUpstreamModule `autowired:""`
|
||||
applicationAuthorizationModule application_authorization.IExportAuthorizationModule `autowired:""`
|
||||
catalogueModule catalogue.IExportCatalogueModule `autowired:""`
|
||||
@@ -114,7 +114,7 @@ func (i *imlExportConfigController) appendFiles(ctx *gin.Context) ([]*ExportFile
|
||||
},
|
||||
{
|
||||
exportFunc: func(ctx *gin.Context) (interface{}, error) {
|
||||
return i.apiModule.ExportAll(ctx)
|
||||
return i.routerModule.ExportAll(ctx)
|
||||
},
|
||||
driver: "api",
|
||||
},
|
||||
|
||||
+10
-14
@@ -6,8 +6,6 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/APIParkLab/APIPark/module/api"
|
||||
api_dto "github.com/APIParkLab/APIPark/module/api/dto"
|
||||
application_authorization "github.com/APIParkLab/APIPark/module/application-authorization"
|
||||
application_authorization_dto "github.com/APIParkLab/APIPark/module/application-authorization/dto"
|
||||
"github.com/APIParkLab/APIPark/module/catalogue"
|
||||
@@ -16,6 +14,8 @@ import (
|
||||
"github.com/APIParkLab/APIPark/module/publish/dto"
|
||||
"github.com/APIParkLab/APIPark/module/release"
|
||||
dto2 "github.com/APIParkLab/APIPark/module/release/dto"
|
||||
"github.com/APIParkLab/APIPark/module/router"
|
||||
router_dto "github.com/APIParkLab/APIPark/module/router/dto"
|
||||
"github.com/APIParkLab/APIPark/module/service"
|
||||
service_dto "github.com/APIParkLab/APIPark/module/service/dto"
|
||||
"github.com/APIParkLab/APIPark/module/subscribe"
|
||||
@@ -52,7 +52,7 @@ type imlImportConfigController struct {
|
||||
teamModule team.ITeamModule `autowired:""`
|
||||
serviceModule service.IServiceModule `autowired:""`
|
||||
appModule service.IAppModule `autowired:""`
|
||||
apiModule api.IApiModule `autowired:""`
|
||||
apiModule router.IRouterModule `autowired:""`
|
||||
upstreamModule upstream.IUpstreamModule `autowired:""`
|
||||
applicationAuthorizationModule application_authorization.IAuthorizationModule `autowired:""`
|
||||
catalogueModule catalogue.ICatalogueModule `autowired:""`
|
||||
@@ -231,14 +231,14 @@ func (i *imlImportConfigController) importApplications(ctx context.Context) erro
|
||||
}
|
||||
|
||||
func (i *imlImportConfigController) importApis(ctx context.Context) error {
|
||||
data, err := unmarshal[api_dto.ExportAPI]("api")
|
||||
data, err := unmarshal[router_dto.Export]("api")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, d := range data {
|
||||
var proxy *api_dto.InputProxy
|
||||
var proxy *router_dto.InputProxy
|
||||
if d.Proxy != nil {
|
||||
proxy = &api_dto.InputProxy{
|
||||
proxy = &router_dto.InputProxy{
|
||||
Path: d.Proxy.Path,
|
||||
Timeout: d.Proxy.Timeout,
|
||||
Retry: d.Proxy.Retry,
|
||||
@@ -253,11 +253,10 @@ func (i *imlImportConfigController) importApis(ctx context.Context) error {
|
||||
if !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return err
|
||||
}
|
||||
_, err = i.apiModule.Create(ctx, d.Service, &api_dto.CreateApi{
|
||||
_, err = i.apiModule.Create(ctx, d.Service, &router_dto.Create{
|
||||
Id: d.Id,
|
||||
Name: d.Name,
|
||||
Path: d.Path,
|
||||
Method: d.Method,
|
||||
Methods: d.Method,
|
||||
Description: d.Description,
|
||||
MatchRules: d.MatchRules,
|
||||
Proxy: proxy,
|
||||
@@ -268,11 +267,8 @@ func (i *imlImportConfigController) importApis(ctx context.Context) error {
|
||||
|
||||
continue
|
||||
}
|
||||
info := &api_dto.EditApi{
|
||||
Info: api_dto.EditInfo{
|
||||
Name: &d.Name,
|
||||
Description: &d.Description,
|
||||
},
|
||||
info := &router_dto.Edit{
|
||||
|
||||
Proxy: proxy,
|
||||
//Doc: &d.Doc,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user