Router FindByRequestURL() fix
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Piotr Biernat 2021-12-18 23:05:42 +01:00 committed by Piotr Biernat
parent a27cc0624a
commit 6392d7088e

View File

@ -38,6 +38,14 @@ func NewRouter(config *config.Config, ds *cache.MemoryDatastore, ttl int) *Route
func (r *Router) FindByRequestURL(url []byte) (bool, *cache.RouteCache) { func (r *Router) FindByRequestURL(url []byte) (bool, *cache.RouteCache) {
var sURL = string(url) var sURL = string(url)
//if cRoute, ok := r.cache[sURL]; ok {
if cRoute, err := r.cache.GetKey("route_" + sURL); err == nil {
return true, cRoute.(*cache.RouteCache)
//response := &cache.RouteCache{} // FIXME #67: Simplify
//ffjson.Unmarshal([]byte(cRoute.(string)), response)
//return true, response // FIXME: redis cache tmp
}
for bID := range r.config.Backends { for bID := range r.config.Backends {
bck := r.config.Backends[bID] bck := r.config.Backends[bID]
if !strings.Contains(sURL, bck.PrefixURL) { if !strings.Contains(sURL, bck.PrefixURL) {
@ -47,14 +55,6 @@ func (r *Router) FindByRequestURL(url []byte) (bool, *cache.RouteCache) {
for rID := range bck.Routes { for rID := range bck.Routes {
rCfg := &bck.Routes[rID] rCfg := &bck.Routes[rID]
//if cRoute, ok := r.cache[sURL]; ok {
if cRoute, err := r.cache.GetKey("route_" + sURL); err == nil {
return true, cRoute.(*cache.RouteCache)
//response := &cache.RouteCache{} // FIXME #67: Simplify
//ffjson.Unmarshal([]byte(cRoute.(string)), response)
//return true, response // FIXME: redis cache tmp
}
regxp := regexp.MustCompile(fmt.Sprintf("%s%s", bck.PrefixURL, rCfg.Pattern)) regxp := regexp.MustCompile(fmt.Sprintf("%s%s", bck.PrefixURL, rCfg.Pattern))
if regxp.Match(url) { if regxp.Match(url) {
tURL := bck.BackendAddress + regxp.ReplaceAllString(sURL, rCfg.Target) tURL := bck.BackendAddress + regxp.ReplaceAllString(sURL, rCfg.Target)