match.go 1.4 KB
Newer Older
E
eoLinker API Management 已提交
1 2 3 4 5 6 7 8 9 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
package strategy_api_manager

import (
	"github.com/eolinker/goku/utils"
	"strings"

	api_manager "github.com/eolinker/goku/goku-node/manager/api-manager"
	node_common "github.com/eolinker/goku/goku-node/node-common"
	entity "github.com/eolinker/goku/server/entity/node-entity"
)

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
}