func GetEnvironment(key string, alternativeKeys ...string) string {
	if value, exists := os.LookupEnv(key); exists {
		return value
	}
	for _, alternativeKey := range alternativeKeys {
		if value, exists := os.LookupEnv(alternativeKey); exists {
			return value
		}
	}
	return ""
}
GetEnvironment retrieves the value of the environment variable named by the key.
If the environment dosen't exist, we will lookup for alternative environment variables
unti we find an environment. Return empty environment value while no environment variables found.
package common
import (
	"fmt"
	"io/ioutil"
	"os"
	"path/filepath"
	"regexp"
)
func GetOrDefault(key, def string, data map[string]string) (result string) {
	var ok bool
	if result, ok = data[key]; !ok {
		result = def
	}
	return
}
func GetReplacement(key string, data map[string]string) (result string) {
	return GetOrDefault(key, key, data)
}
func PathExists(path string) (bool, error) {
	_, err := os.Stat(path)
	if err == nil {
		return true, nil
	}
	if os.IsNotExist(err) {
		return false, nil
	}
	return false, err
}
const (
	PrivateFileMode = 0600
	PrivateDirMode = 0700
)
func IsDirWriteable(dir string) error {
	f := filepath.Join(dir, ".touch")
	if err := ioutil.WriteFile(f, []byte(""), PrivateFileMode); err != nil {
		return err
	}
	return os.Remove(f)
}
func CheckDirPermission(dir string, perm os.FileMode) error {
	if !Exist(dir) {
		return fmt.Errorf("directory %q empty, cannot check permission", dir)
	}
	dirInfo, err := os.Stat(dir)
	if err != nil {
		return err
	}
	dirMode := dirInfo.Mode().Perm()
	if dirMode != perm {
		err = fmt.Errorf("directory %q exist, but the permission is %q. The recommended permission is %q to prevent possible unprivileged access to the data", dir, dirInfo.Mode(), os.FileMode(PrivateDirMode))
		return err
	}
	return nil
}
func Exist(name string) bool {
	_, err := os.Stat(name)
	return err == nil
}
func ParseVersionNum(release string) string {
	return regexp.MustCompile(`^.*v`).ReplaceAllString(release, "")
}