Add functions to get endpoint from list by name and by id

This commit is contained in:
Juan Carlos Mejías Rodríguez 2019-08-15 22:40:56 -04:00
parent a6f4f88fd2
commit 6c4ecb1c90

View File

@ -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()