From 6c4ecb1c90918b77cc82cf2053840ed1a715442d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Carlos=20Mej=C3=ADas=20Rodr=C3=ADguez?= Date: Thu, 15 Aug 2019 22:40:56 -0400 Subject: [PATCH] Add functions to get endpoint from list by name and by id --- common/utils.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/common/utils.go b/common/utils.go index 44bd647..aa01a76 100644 --- a/common/utils.go +++ b/common/utils.go @@ -92,6 +92,24 @@ func GetEndpointByName(name string) (endpoint portainer.Endpoint, err error) { return } +func GetEndpointFromListById(endpoints []portainer.Endpoint, id portainer.EndpointID) (endpoint portainer.Endpoint, err error) { + for i := range endpoints { + if endpoints[i].ID == id { + return endpoints[i], err + } + } + return endpoint, ErrEndpointNotFound +} + +func GetEndpointFromListByName(endpoints []portainer.Endpoint, name string) (endpoint portainer.Endpoint, err error) { + for i := range endpoints { + if endpoints[i].Name == name { + return endpoints[i], err + } + } + return endpoint, ErrEndpointNotFound +} + func GetEndpointSwarmClusterId(endpointId portainer.EndpointID) (endpointSwarmClusterId string, err error) { // Get docker information for endpoint portainerClient, err := GetClient()