simple_env.go 720 B

12345678910111213141516171819202122232425
  1. package lookup
  2. import (
  3. "fmt"
  4. "os"
  5. "github.com/docker/libcompose/config"
  6. )
  7. // OsEnvLookup is a "bare" structure that implements the project.EnvironmentLookup interface
  8. type OsEnvLookup struct {
  9. }
  10. // Lookup creates a string slice of string containing a "docker-friendly" environment string
  11. // in the form of 'key=value'. It gets environment values using os.Getenv.
  12. // If the os environment variable does not exists, the slice is empty. serviceName and config
  13. // are not used at all in this implementation.
  14. func (o *OsEnvLookup) Lookup(key, serviceName string, config *config.ServiceConfig) []string {
  15. ret := os.Getenv(key)
  16. if ret == "" {
  17. return []string{}
  18. }
  19. return []string{fmt.Sprintf("%s=%s", key, ret)}
  20. }