Skip to content

Commit

Permalink
external first step
Browse files Browse the repository at this point in the history
  • Loading branch information
lovehunter9 committed Sep 2, 2024
1 parent e517cd5 commit 1bf1c59
Showing 1 changed file with 38 additions and 17 deletions.
55 changes: 38 additions & 17 deletions packages/gateway/pkg/proxy/backend_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,30 +179,49 @@ func (p *BackendProxy) addHandlers(route string, handler GatewayHandler) {
}
}

func minWithNegativeOne(a, b int, aName, bName string) (int, string) {
if a == -1 && b == -1 {
return -1, ""
}

if a == -1 {
return b, bName
}
if b == -1 {
return a, aName
//func minWithNegativeOne(a, b int, aName, bName string) (int, string) {
// if a == -1 && b == -1 {
// return -1, ""
// }
//
// if a == -1 {
// return b, bName
// }
// if b == -1 {
// return a, aName
// }
//
// if a < b {
// return a, aName
// } else {
// return b, bName
// }
//}

func minWithNegativeOne(values []int, names []string) (int, string) {
minValue := -1
minName := ""

for i, value := range values {
if value != -1 {
if minValue == -1 || value < minValue {
minValue = value
minName = names[i]
}
}
}

if a < b {
return a, aName
} else {
return b, bName
}
return minValue, minName
}

func rewriteUrl(path string, pvc string, prefix string) string {
if prefix == "" {
homeIndex := strings.Index(path, "/Home")
applicationIndex := strings.Index(path, "/Application")
splitIndex, splitName := minWithNegativeOne(homeIndex, applicationIndex, "/Home", "/Application")
externalIndex := strings.Index(path, "/external")
splitIndex, splitName := minWithNegativeOne(
[]int{homeIndex, applicationIndex, externalIndex},
[]string{"/Home", "/Application", "/external"})
if splitIndex != -1 {
firstHalf := path[:splitIndex]
secondHalf := path[splitIndex:]
Expand All @@ -214,9 +233,11 @@ func rewriteUrl(path string, pvc string, prefix string) string {
}
if splitName == "/Home" {
return firstHalf + "/" + pvc + secondHalf
} else {
} else if splitName == "/Application" {
secondHalf = strings.TrimPrefix(path[splitIndex:], splitName)
return firstHalf + "/" + pvc + "/Data" + secondHalf
} else if splitName == "/external" {
return firstHalf + secondHalf
}
}
} else {
Expand Down

0 comments on commit 1bf1c59

Please sign in to comment.