composable.go 823 B

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