Skip to content

Commit

Permalink
OAS-9904 Review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jwierzbo committed Aug 26, 2024
1 parent f223c88 commit 6a6be7e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 35 deletions.
43 changes: 8 additions & 35 deletions pkg/deployment/resources/gateway_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ package resources
import (
"fmt"
"net/url"
"sort"
"strconv"
"time"

Expand All @@ -41,13 +40,16 @@ import (
"sigs.k8s.io/yaml"

shared "github.com/arangodb/kube-arangodb/pkg/apis/shared"
"github.com/arangodb/kube-arangodb/pkg/util"
)

type Redirect KV[string, []string]
type Redirect util.KV[string, []string]

type KV[K comparable, V any] struct {
K K
V V
func WithRedirect(prefix string, target ...string) Redirect {
return Redirect{
K: prefix,
V: target,
}
}

func RenderGatewayConfigYAML(dbServiceAddress string, redirects ...Redirect) ([]byte, error) {
Expand Down Expand Up @@ -186,7 +188,7 @@ func RenderConfig(dbServiceAddress string, redirects ...Redirect) (*bootstrapAPI
routes = append(routes, route)
}

routes = Sort(routes, func(i, j *routeAPI.Route) bool {
routes = util.Sort(routes, func(i, j *routeAPI.Route) bool {
return i.Match.GetPrefix() > j.Match.GetPrefix()
})

Expand Down Expand Up @@ -264,32 +266,3 @@ func RenderConfig(dbServiceAddress string, redirects ...Redirect) (*bootstrapAPI
},
}, nil
}

func Extract[K comparable, V any](in map[K]V) []KV[K, V] {
r := make([]KV[K, V], 0, len(in))

for k, v := range in {
r = append(r, KV[K, V]{
K: k,
V: v,
})
}

return r
}

func Sort[IN any](in []IN, cmp func(i, j IN) bool) []IN {
r := make([]IN, len(in))
copy(r, in)
sort.Slice(r, func(i, j int) bool {
return cmp(r[i], r[j])
})
return r
}

func WithRedirect(prefix string, target ...string) Redirect {
return Redirect{
K: prefix,
V: target,
}
}
27 changes: 27 additions & 0 deletions pkg/util/dict.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,33 @@ import (
"sort"
)

type KV[K comparable, V any] struct {
K K
V V
}

func Extract[K comparable, V any](in map[K]V) []KV[K, V] {
r := make([]KV[K, V], 0, len(in))

for k, v := range in {
r = append(r, KV[K, V]{
K: k,
V: v,
})
}

return r
}

func Sort[IN any](in []IN, cmp func(i, j IN) bool) []IN {
r := make([]IN, len(in))
copy(r, in)
sort.Slice(r, func(i, j int) bool {
return cmp(r[i], r[j])
})
return r
}

func SortKeys(m interface{}) []string {
if m == nil {
return []string{}
Expand Down

0 comments on commit 6a6be7e

Please sign in to comment.