traefik/vendor/github.com/docker/libcompose/lookup/envfile.go

32 lines
802 B
Go
Raw Normal View History

2017-02-07 21:33:23 +00:00
package lookup
import (
"strings"
2018-01-22 11:16:03 +00:00
"github.com/docker/cli/opts"
2017-02-07 21:33:23 +00:00
"github.com/docker/libcompose/config"
)
// EnvfileLookup is a structure that implements the project.EnvironmentLookup interface.
// It holds the path of the file where to lookup environment values.
type EnvfileLookup struct {
Path string
}
// Lookup creates a string slice of string containing a "docker-friendly" environment string
// in the form of 'key=value'. It gets environment values using a '.env' file in the specified
// path.
func (l *EnvfileLookup) Lookup(key string, config *config.ServiceConfig) []string {
2017-02-07 21:33:23 +00:00
envs, err := opts.ParseEnvFile(l.Path)
if err != nil {
return []string{}
}
for _, env := range envs {
e := strings.Split(env, "=")
if e[0] == key {
return []string{env}
}
}
return []string{}
}