mirror of
https://github.com/docker/compose.git
synced 2026-02-09 01:59:22 +08:00
replace some uses of strings.Split(N) for strings.Cut
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
committed by
Nicolas De loof
parent
fa7549a851
commit
c51b1fea29
@@ -774,11 +774,10 @@ func (s *composeService) getLinks(ctx context.Context, projectName string, servi
|
||||
}
|
||||
|
||||
for _, rawLink := range service.Links {
|
||||
linkSplit := strings.Split(rawLink, ":")
|
||||
linkServiceName := linkSplit[0]
|
||||
linkName := linkServiceName
|
||||
if len(linkSplit) == 2 {
|
||||
linkName = linkSplit[1] // linkName if informed like in: "serviceName:linkName"
|
||||
// linkName if informed like in: "serviceName[:linkName]"
|
||||
linkServiceName, linkName, ok := strings.Cut(rawLink, ":")
|
||||
if !ok {
|
||||
linkName = linkServiceName
|
||||
}
|
||||
cnts, err := getServiceContainers(linkServiceName)
|
||||
if err != nil {
|
||||
@@ -810,11 +809,9 @@ func (s *composeService) getLinks(ctx context.Context, projectName string, servi
|
||||
}
|
||||
|
||||
for _, rawExtLink := range service.ExternalLinks {
|
||||
extLinkSplit := strings.Split(rawExtLink, ":")
|
||||
externalLink := extLinkSplit[0]
|
||||
linkName := externalLink
|
||||
if len(extLinkSplit) == 2 {
|
||||
linkName = extLinkSplit[1]
|
||||
externalLink, linkName, ok := strings.Cut(rawExtLink, ":")
|
||||
if !ok {
|
||||
linkName = externalLink
|
||||
}
|
||||
links = append(links, format(externalLink, linkName))
|
||||
}
|
||||
|
||||
@@ -317,15 +317,15 @@ func splitCpArg(arg string) (ctr, path string) {
|
||||
return "", arg
|
||||
}
|
||||
|
||||
parts := strings.SplitN(arg, ":", 2)
|
||||
ctr, path, ok := strings.Cut(arg, ":")
|
||||
|
||||
if len(parts) == 1 || strings.HasPrefix(parts[0], ".") {
|
||||
if !ok || strings.HasPrefix(ctr, ".") {
|
||||
// Either there's no `:` in the arg
|
||||
// OR it's an explicit local relative path like `./file:name.txt`.
|
||||
return "", arg
|
||||
}
|
||||
|
||||
return parts[0], parts[1]
|
||||
return ctr, path
|
||||
}
|
||||
|
||||
func resolveLocalPath(localPath string) (absPath string, err error) {
|
||||
|
||||
@@ -241,11 +241,8 @@ func (s *composeService) getCreateConfigs(ctx context.Context,
|
||||
} // VOLUMES/MOUNTS/FILESYSTEMS
|
||||
tmpfs := map[string]string{}
|
||||
for _, t := range service.Tmpfs {
|
||||
if arr := strings.SplitN(t, ":", 2); len(arr) > 1 {
|
||||
tmpfs[arr[0]] = arr[1]
|
||||
} else {
|
||||
tmpfs[arr[0]] = ""
|
||||
}
|
||||
k, v, _ := strings.Cut(t, ":")
|
||||
tmpfs[k] = v
|
||||
}
|
||||
binds, mounts, err := s.buildContainerVolumes(ctx, *p, service, inherit)
|
||||
if err != nil {
|
||||
@@ -563,13 +560,13 @@ func defaultNetworkSettings(project *types.Project,
|
||||
func getRestartPolicy(service types.ServiceConfig) container.RestartPolicy {
|
||||
var restart container.RestartPolicy
|
||||
if service.Restart != "" {
|
||||
split := strings.Split(service.Restart, ":")
|
||||
name, num, ok := strings.Cut(service.Restart, ":")
|
||||
var attempts int
|
||||
if len(split) > 1 {
|
||||
attempts, _ = strconv.Atoi(split[1])
|
||||
if ok {
|
||||
attempts, _ = strconv.Atoi(num)
|
||||
}
|
||||
restart = container.RestartPolicy{
|
||||
Name: mapRestartPolicyCondition(split[0]),
|
||||
Name: mapRestartPolicyCondition(name),
|
||||
MaximumRetryCount: attempts,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user