portainer/portainer

View on GitHub
api/http/handler/endpoints/unique_name.go

Summary

Maintainability
A
0 mins
Test Coverage
package endpoints

import portainer "github.com/portainer/portainer/api"

func (handler *Handler) isNameUnique(name string, endpointID portainer.EndpointID) (bool, error) {
    endpoints, err := handler.DataStore.Endpoint().Endpoints()
    if err != nil {
        return false, err
    }

    for _, endpoint := range endpoints {
        if endpoint.Name == name && (endpointID == 0 || endpoint.ID != endpointID) {
            return false, nil
        }
    }

    return true, nil
}