github.com/docker/libcompose@v0.4.1-0.20210616120443-2a046c0bdbf2/lookup/composable.go (about)

     1  package lookup
     2  
     3  import (
     4  	"github.com/docker/libcompose/config"
     5  )
     6  
     7  // ComposableEnvLookup is a structure that implements the project.EnvironmentLookup interface.
     8  // It holds an ordered list of EnvironmentLookup to call to look for the environment value.
     9  type ComposableEnvLookup struct {
    10  	Lookups []config.EnvironmentLookup
    11  }
    12  
    13  // Lookup creates a string slice of string containing a "docker-friendly" environment string
    14  // in the form of 'key=value'. It loop through the lookups and returns the latest value if
    15  // more than one lookup return a result.
    16  func (l *ComposableEnvLookup) Lookup(key string, config *config.ServiceConfig) []string {
    17  	result := []string{}
    18  	for _, lookup := range l.Lookups {
    19  		env := lookup.Lookup(key, config)
    20  		if len(env) == 1 {
    21  			result = env
    22  		}
    23  	}
    24  	return result
    25  }