From 3e485c315216e6530c3bddcb0320b13db4885686 Mon Sep 17 00:00:00 2001 From: Matt Hook Date: Wed, 7 Dec 2022 17:15:52 +1300 Subject: [PATCH] feat(api): remove golang experimental packages [EE-3648] (#8081) * remove golang experimental packages * rebase and fix references --- api/go.mod | 5 ++--- api/go.sum | 2 -- .../containers/container_gpus_inspect.go | 2 +- api/http/handler/endpoints/filter.go | 2 +- api/internal/slices/slices.go | 22 +++++++++++++++++++ 5 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 api/internal/slices/slices.go diff --git a/api/go.mod b/api/go.mod index c544623dc..55779c6ac 100644 --- a/api/go.mod +++ b/api/go.mod @@ -37,13 +37,14 @@ require ( github.com/portainer/docker-compose-wrapper v0.0.0-20220708023447-a69a4ebaa021 github.com/portainer/libcrypto v0.0.0-20220506221303-1f4fb3b30f9a github.com/portainer/libhttp v0.0.0-20220916153711-5d61e12f4b0a + github.com/portainer/portainer/pkg/libhelm v0.0.0-20221201012749-4fee35924724 + github.com/portainer/portainer/third_party/digest v0.0.0-20221201002639-8fd0efa34f73 github.com/robfig/cron/v3 v3.0.1 github.com/rs/zerolog v1.28.0 github.com/stretchr/testify v1.8.0 github.com/viney-shih/go-lock v1.1.1 go.etcd.io/bbolt v1.3.6 golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd - golang.org/x/exp v0.0.0-20220613132600-b0d781184e0d golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 golang.org/x/sync v0.0.0-20210220032951-036812b2e83c gopkg.in/alecthomas/kingpin.v2 v2.2.6 @@ -110,8 +111,6 @@ require ( github.com/opencontainers/go-digest v1.0.0 // indirect github.com/opencontainers/image-spec v1.0.2 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/portainer/portainer/third_party/digest v0.0.0-20221201002639-8fd0efa34f73 // indirect - github.com/portainer/portainer/pkg/libhelm v0.0.0-20221201012749-4fee35924724 // indirect github.com/sergi/go-diff v1.1.0 // indirect github.com/sirupsen/logrus v1.8.1 // indirect github.com/spf13/pflag v1.0.5 // indirect diff --git a/api/go.sum b/api/go.sum index 8478aeb8d..d050d2790 100644 --- a/api/go.sum +++ b/api/go.sum @@ -424,8 +424,6 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0 golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= -golang.org/x/exp v0.0.0-20220613132600-b0d781184e0d h1:vtUKgx8dahOomfFzLREU8nSv25YHnTgLBn4rDnWZdU0= -golang.org/x/exp v0.0.0-20220613132600-b0d781184e0d/go.mod h1:Kr81I6Kryrl9sr8s2FK3vxD90NdsKWRuOIl2O4CvYbA= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= diff --git a/api/http/handler/docker/containers/container_gpus_inspect.go b/api/http/handler/docker/containers/container_gpus_inspect.go index 9329c35c5..2623a0fa4 100644 --- a/api/http/handler/docker/containers/container_gpus_inspect.go +++ b/api/http/handler/docker/containers/container_gpus_inspect.go @@ -10,7 +10,7 @@ import ( "github.com/portainer/libhttp/response" portainer "github.com/portainer/portainer/api" "github.com/portainer/portainer/api/http/middlewares" - "golang.org/x/exp/slices" + "github.com/portainer/portainer/api/internal/slices" ) type containerGpusResponse struct { diff --git a/api/http/handler/endpoints/filter.go b/api/http/handler/endpoints/filter.go index 7fb787185..dc9a6e74f 100644 --- a/api/http/handler/endpoints/filter.go +++ b/api/http/handler/endpoints/filter.go @@ -11,7 +11,7 @@ import ( "github.com/portainer/libhttp/request" portainer "github.com/portainer/portainer/api" "github.com/portainer/portainer/api/internal/endpointutils" - "golang.org/x/exp/slices" + "github.com/portainer/portainer/api/internal/slices" ) type EnvironmentsQuery struct { diff --git a/api/internal/slices/slices.go b/api/internal/slices/slices.go new file mode 100644 index 000000000..b0591c861 --- /dev/null +++ b/api/internal/slices/slices.go @@ -0,0 +1,22 @@ +package slices + +// Contains is a generic function that returns true if the element is contained within the slice +func Contains[T comparable](elems []T, v T) bool { + for _, s := range elems { + if v == s { + return true + } + } + return false +} + +// IndexFunc returns the first index i satisfying f(s[i]), +// or -1 if none do. +func IndexFunc[E any](s []E, f func(E) bool) int { + for i, v := range s { + if f(v) { + return i + } + } + return -1 +}