mirror of
https://github.com/APIParkLab/APIPark.git
synced 2026-06-04 10:13:53 +08:00
修复更新集群时配置不重新初始化的问题
This commit is contained in:
@@ -4,9 +4,9 @@ import (
|
||||
"fmt"
|
||||
"net/textproto"
|
||||
"strings"
|
||||
|
||||
|
||||
"github.com/APIParkLab/APIPark/common"
|
||||
|
||||
|
||||
"github.com/APIParkLab/APIPark/common/enum"
|
||||
"github.com/APIParkLab/APIPark/gateway"
|
||||
)
|
||||
@@ -26,6 +26,7 @@ type Router struct {
|
||||
Retry int `json:"retry"`
|
||||
TimeOut int `json:"time_out"`
|
||||
Labels map[string]string `json:"labels"`
|
||||
Disable bool `json:"disable"`
|
||||
}
|
||||
|
||||
type Rule struct {
|
||||
@@ -79,7 +80,7 @@ func ToRouter(r *gateway.ApiRelease, version string, matches map[string]string)
|
||||
//若请求路径包含restful参数
|
||||
if common.IsRestfulPath(r.Path) {
|
||||
rewritePlugin.PathType = "regex" //正则替换
|
||||
|
||||
|
||||
//如果转发路径包含restful参数
|
||||
if common.IsRestfulPath(r.ProxyPath) {
|
||||
r.ProxyPath = formatProxyPath(r.Path, r.ProxyPath)
|
||||
@@ -100,7 +101,7 @@ func ToRouter(r *gateway.ApiRelease, version string, matches map[string]string)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
rules := make([]*Rule, 0, len(r.Rules))
|
||||
for _, m := range r.Rules {
|
||||
rule := &Rule{
|
||||
@@ -108,11 +109,11 @@ func ToRouter(r *gateway.ApiRelease, version string, matches map[string]string)
|
||||
Name: m.Key,
|
||||
Value: "",
|
||||
}
|
||||
|
||||
|
||||
if m.Position == enum.MatchPositionHeader {
|
||||
rule.Name = textproto.CanonicalMIMEHeaderKey(rule.Name)
|
||||
}
|
||||
|
||||
|
||||
switch m.MatchType {
|
||||
case enum.MatchTypeEqual:
|
||||
rule.Value = m.Pattern
|
||||
@@ -137,7 +138,7 @@ func ToRouter(r *gateway.ApiRelease, version string, matches map[string]string)
|
||||
case enum.MatchTypeAny:
|
||||
rule.Value = "*"
|
||||
}
|
||||
|
||||
|
||||
rules = append(rules, rule)
|
||||
}
|
||||
plugin := map[string]*Plugin{
|
||||
@@ -160,7 +161,11 @@ func ToRouter(r *gateway.ApiRelease, version string, matches map[string]string)
|
||||
if r.Labels != nil {
|
||||
labels = r.Labels
|
||||
}
|
||||
|
||||
protocols := []string{"http", "https"}
|
||||
if len(r.Protocols) > 0 {
|
||||
protocols = r.Protocols
|
||||
}
|
||||
|
||||
return &Router{
|
||||
BasicInfo: &BasicInfo{
|
||||
ID: fmt.Sprintf("%s@router", r.ID),
|
||||
@@ -170,8 +175,9 @@ func ToRouter(r *gateway.ApiRelease, version string, matches map[string]string)
|
||||
Version: version,
|
||||
Matches: matches,
|
||||
},
|
||||
Host: hosts,
|
||||
Method: r.Method,
|
||||
Host: hosts,
|
||||
Method: r.Methods,
|
||||
|
||||
Location: r.Path,
|
||||
Rules: rules,
|
||||
Service: r.Service,
|
||||
@@ -179,7 +185,8 @@ func ToRouter(r *gateway.ApiRelease, version string, matches map[string]string)
|
||||
Retry: r.Retry,
|
||||
TimeOut: r.Timeout,
|
||||
Labels: labels,
|
||||
Protocols: []string{"http", "https"},
|
||||
Protocols: protocols,
|
||||
Disable: r.Disable,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,7 +202,7 @@ func formatProxyPath(requestPath, proxyPath string) string {
|
||||
i += 1
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for param, order := range restfulSet {
|
||||
newProxyPath = strings.ReplaceAll(newProxyPath, param, order)
|
||||
}
|
||||
|
||||
+8
-4
@@ -34,9 +34,11 @@ type ProjectRelease struct {
|
||||
|
||||
type ApiRelease struct {
|
||||
*BasicItem
|
||||
Path string
|
||||
Method []string
|
||||
Host []string
|
||||
Path string
|
||||
Methods []string
|
||||
Host []string
|
||||
Protocols []string
|
||||
|
||||
Plugins map[string]*Plugin
|
||||
Service string
|
||||
Rules []*MatchRule
|
||||
@@ -45,7 +47,9 @@ type ApiRelease struct {
|
||||
ProxyHeaders []*ProxyHeader
|
||||
Retry int
|
||||
Timeout int
|
||||
Labels map[string]string
|
||||
|
||||
Labels map[string]string
|
||||
Disable bool
|
||||
}
|
||||
|
||||
type ProxyHeader struct {
|
||||
|
||||
+14
-4
@@ -71,7 +71,15 @@ func (m *imlPublishModule) initGateway(ctx context.Context, partitionId string,
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
apiIds := utils.SliceToSlice(releaseInfo.Apis, func(api *gateway.ApiRelease) string {
|
||||
return api.ID
|
||||
})
|
||||
clientDriver.Service().Online(ctx, &gateway.ServiceRelease{
|
||||
ID: releaseInfo.Id,
|
||||
Apis: apiIds,
|
||||
})
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -127,9 +135,11 @@ func (m *imlPublishModule) getProjectRelease(ctx context.Context, projectID stri
|
||||
Description: a.Description,
|
||||
Version: version,
|
||||
},
|
||||
Path: a.Path,
|
||||
Method: a.Methods,
|
||||
Service: a.Service,
|
||||
Path: a.Path,
|
||||
Methods: a.Methods,
|
||||
Service: a.Service,
|
||||
Protocols: a.Protocols,
|
||||
Disable: a.Disable,
|
||||
}
|
||||
proxy, ok := proxyCommitMap[a.UUID]
|
||||
if ok {
|
||||
@@ -220,7 +230,7 @@ func (m *imlPublishModule) getReleaseInfo(ctx context.Context, projectID, releas
|
||||
Version: version,
|
||||
},
|
||||
Path: a.Path,
|
||||
Method: a.Methods,
|
||||
Methods: a.Methods,
|
||||
Service: a.Service,
|
||||
}
|
||||
proxy, ok := proxyCommitMap[a.UUID]
|
||||
|
||||
@@ -77,7 +77,7 @@ func (i *imlSubscribeModule) getSubscribers(ctx context.Context, serviceIds []st
|
||||
}), nil
|
||||
}
|
||||
|
||||
func (i *imlSubscribeModule) initGateway(ctx context.Context, clientDriver gateway.IClientDriver) error {
|
||||
func (i *imlSubscribeModule) initGateway(ctx context.Context, clusterId string, clientDriver gateway.IClientDriver) error {
|
||||
|
||||
projects, err := i.serviceService.List(ctx)
|
||||
if err != nil {
|
||||
|
||||
@@ -2,6 +2,7 @@ package subscribe
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/APIParkLab/APIPark/gateway"
|
||||
"github.com/APIParkLab/APIPark/module/system"
|
||||
"reflect"
|
||||
|
||||
@@ -54,6 +55,8 @@ type IExportSubscribeApprovalModule interface {
|
||||
func init() {
|
||||
subscribeModule := new(imlSubscribeModule)
|
||||
autowire.Auto[ISubscribeModule](func() reflect.Value {
|
||||
|
||||
gateway.RegisterInitHandleFunc(subscribeModule.initGateway)
|
||||
return reflect.ValueOf(subscribeModule)
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user