Add a search string to envs

This commit is contained in:
Nikolai Rodionov 2024-05-05 21:07:12 +02:00
parent dad038fe29
commit e71636896e
Signed by: allanger
GPG Key ID: 0AA46A90E25592AD
3 changed files with 15 additions and 5 deletions

2
go.mod
View File

@ -148,7 +148,7 @@ require (
)
require (
git.badhouseplants.net/softplayer/softplayer-go-proto v0.1.10
git.badhouseplants.net/softplayer/softplayer-go-proto v0.1.11
github.com/golang/protobuf v1.5.4
golang.org/x/net v0.24.0 // indirect
golang.org/x/sys v0.19.0 // indirect

4
go.sum
View File

@ -1,6 +1,6 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
git.badhouseplants.net/softplayer/softplayer-go-proto v0.1.10 h1:vyI425BM85gyUi23HXJQtMw/pC81wYhWgBKgmG3Lc2w=
git.badhouseplants.net/softplayer/softplayer-go-proto v0.1.10/go.mod h1:OU+833cHwvecr+gsnPEKQYlAJbpL8bqSJVLobdw63qI=
git.badhouseplants.net/softplayer/softplayer-go-proto v0.1.11 h1:Kjdz7HUOhg5f8wktvf+QG6SNv0sN3OXfz9yErwrfl38=
git.badhouseplants.net/softplayer/softplayer-go-proto v0.1.11/go.mod h1:OU+833cHwvecr+gsnPEKQYlAJbpL8bqSJVLobdw63qI=
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 h1:bvDV9vkmnHYOMsOr4WLk+Vo07yKIzd94sVoIqshQ4bU=
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24/go.mod h1:8o94RPi1/7XTJvwPpRSzSUedZrtlirdB3r9Z20bi2f8=
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8=

View File

@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"log"
"strings"
"github.com/google/uuid"
"github.com/joho/godotenv"
@ -213,7 +214,7 @@ func (env *Environemnt) Delete(ctx context.Context) error {
return nil
}
func (env *Environemnt) ListEnvs(ctx context.Context) ([]*Environemnt, error) {
func (env *Environemnt) ListEnvs(ctx context.Context, searchString string) ([]*Environemnt, error) {
env.Controller.GetClient()
conf := &rest.Config{
Host: "https://kubernetes.default.svc.cluster.local:443",
@ -244,8 +245,17 @@ func (env *Environemnt) ListEnvs(ctx context.Context) ([]*Environemnt, error) {
if err := i.Get(ctx); err != nil {
return nil, err
}
if len(searchString) > 0 {
if strings.Contains(i.Data.Name, searchString) {
result = append(result, i)
}
if strings.Contains(i.Data.Description, searchString) {
result = append(result, i)
}
} else {
result = append(result, i)
}
}
return result, nil
}