match.go 1.4 KB
Newer Older
E
eoLinker API Management 已提交
1 2 3
package strategy_api_manager

import (
黄孟柱 已提交
4
	"github.com/eolinker/goku-api-gateway/utils"
E
eoLinker API Management 已提交
5 6
	"strings"

黄孟柱 已提交
7 8 9
	api_manager "github.com/eolinker/goku-api-gateway/goku-node/manager/api-manager"
	node_common "github.com/eolinker/goku-api-gateway/goku-node/node-common"
	entity "github.com/eolinker/goku-api-gateway/server/entity/node-entity"
E
eoLinker API Management 已提交
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
)

func CheckApiFromStrategy(strategyId, requestPath string, requestMethod string) (*entity.ApiExtend, string, []string, bool) {
	apiMap, has := getAPis(strategyId)
	if !has {
		return nil, "", nil, false
	}
	for _, strategyApi := range apiMap.apis {
		apiInfo, has := api_manager.GetAPI(strategyApi.ApiId)
		if !has {
			continue
		}
		if apiInfo.StripSlash {
			requestPath = node_common.FilterSlash(requestPath)
			apiInfo.RequestURL = node_common.FilterSlash(apiInfo.RequestURL)
		}

		isMatch, splitURL, param := node_common.MatchURI(requestPath, apiInfo.RequestURL)
		if isMatch {
			method := strings.ToUpper(apiInfo.RequestMethod)
			if strings.Contains(method, requestMethod) {
				apiextend := &entity.ApiExtend{Api: apiInfo}

				if strategyApi.Target != "" {
					apiextend.Target = strategyApi.Target
				} else {
					apiextend.Target = apiInfo.BalanceName
				}

Y
Your Name 已提交
39
				apiextend.Target = utils.TrimSuffixAll(apiextend.Target, "/")
E
eoLinker API Management 已提交
40 41 42 43 44 45 46 47

				//apiextend.TargetServer = balance_manager.ParseTargetServer(apiextend.Target)
				return apiextend, splitURL, param, true
			}
		}
	}
	return nil, "", nil, false
}