From 22aee0387a12e6cdebbc08c6bae3b459e6498f40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorben=20G=C3=BCnther?= Date: Mon, 14 Aug 2023 16:50:15 +0200 Subject: [PATCH] functions: Substitute with "slices" package --- functions/functions.go | 12 ------------ graph/schema.resolvers.go | 6 +++--- 2 files changed, 3 insertions(+), 15 deletions(-) delete mode 100644 functions/functions.go diff --git a/functions/functions.go b/functions/functions.go deleted file mode 100644 index 6de49df..0000000 --- a/functions/functions.go +++ /dev/null @@ -1,12 +0,0 @@ -package functions - -// SliceContains checks if slice s contains element e and returns index -func SliceContains(s []string, e string) (bool, int) { - for i, v := range s { - if e == v { - return true, i - } - } - - return false, 0 -} diff --git a/graph/schema.resolvers.go b/graph/schema.resolvers.go index 00d9c98..269bb8f 100644 --- a/graph/schema.resolvers.go +++ b/graph/schema.resolvers.go @@ -14,10 +14,10 @@ import ( "log/slog" "math/rand" "net/http" + "slices" "time" "git.xenrox.net/~xenrox/10man-api/database" - "git.xenrox.net/~xenrox/10man-api/functions" "git.xenrox.net/~xenrox/10man-api/graph/generated" "git.xenrox.net/~xenrox/10man-api/graph/model" "git.xenrox.net/~xenrox/10man-api/logic" @@ -460,8 +460,8 @@ func (r *mutationResolver) VetoMap(ctx context.Context, mapArg *string) (*model. length := len(voteMaps) // check if voted map is in remaining - contains, i := functions.SliceContains(voteMaps, *mapArg) - if !contains { + i := slices.Index(voteMaps, *mapArg) + if i == -1 { return nil, errors.New("no legal vote") } voteMaps[i] = voteMaps[length-1] -- 2.44.0