github.com/CPtung/libcompose@v0.4.3/project/utils.go (about) 1 package project 2 3 import ( 4 "strings" 5 ) 6 7 // DefaultDependentServices return the dependent services (as an array of ServiceRelationship) 8 // for the specified project and service. It looks for : links, volumesFrom, net and ipc configuration. 9 func DefaultDependentServices(p *Project, s Service) []ServiceRelationship { 10 config := s.Config() 11 if config == nil { 12 return []ServiceRelationship{} 13 } 14 15 result := []ServiceRelationship{} 16 for _, link := range config.Links { 17 result = append(result, NewServiceRelationship(link, RelTypeLink)) 18 } 19 20 for _, volumesFrom := range config.VolumesFrom { 21 result = append(result, NewServiceRelationship(volumesFrom, RelTypeVolumesFrom)) 22 } 23 24 for _, dependsOn := range config.DependsOn { 25 result = append(result, NewServiceRelationship(dependsOn, RelTypeDependsOn)) 26 } 27 28 if config.NetworkMode != "" { 29 if strings.HasPrefix(config.NetworkMode, "service:") { 30 serviceName := config.NetworkMode[8:] 31 result = append(result, NewServiceRelationship(serviceName, RelTypeNetworkMode)) 32 } 33 } 34 35 return result 36 } 37 38 // NameAlias returns the name and alias based on the specified string. 39 // If the name contains a colon (like name:alias) it will split it, otherwise 40 // it will return the specified name as name and alias. 41 func NameAlias(name string) (string, string) { 42 parts := strings.SplitN(name, ":", 2) 43 if len(parts) == 2 { 44 return parts[0], parts[1] 45 } 46 return parts[0], parts[0] 47 }