github.com/direnv/go-lpenv@v0.0.0-20201224120758-54c33c5ae6e4/getenv_windows.go (about)

     1  package lpenv
     2  
     3  import "strings"
     4  
     5  // Getenv looks for the key in the given environment variables
     6  //
     7  // The Windows implementation is case-insensitive.
     8  func Getenv(env []string, key string) string {
     9  	if len(key) == 0 {
    10  		return ""
    11  	}
    12  
    13  	prefix := strings.ToLower(key + "=")
    14  	for _, pair := range env {
    15  		if len(pair) > len(prefix) && prefix == strings.ToLower(pair[:len(prefix)]) {
    16  			return pair[len(prefix):]
    17  		}
    18  	}
    19  	return ""
    20  }