func appName() string {
	if App == "" {
		fileName := filepath.Base(os.Args[0])
		fileExt := filepath.Ext(fileName)
		if len(fileExt) > 0 {
			fileName = strings.Split(fileName, ".")[0]
		}
		App = regexp.MustCompile("[^a-zA-Z0-9_]").ReplaceAllString(fileName, "_")
	}
	return App
}
appName returns the name of the application, with path and extension stripped off,
and all characters other than ASCII letters, numbers, or underscores, replaced by
underscores.
Replacing special characters by underscores makes the returned name suitable for
being used in the name of an environment variable.
appName does all this only once and returns the created app name on subsequent calls.
package start
import (
	"os"
	"path/filepath"
	"regexp"
	"runtime"
	"strings"
	"github.com/laurent22/toml-go"
)
func newConfigFile(filename string) (*configFile, error) {  
	cfg := &configFile{}
	err := cfg.findAndReadTomlFile(filename)
	return cfg, err
}
func (c *configFile) String(name string) string {
	value, exists := c.doc.GetValue(name)
	if exists {
		return strings.Trim(value.String(), "\"")
	}
	return ""
}
func (c *configFile) Path() string {
	if c == nil {
		return ""
	}
	return c.path
}
func (c *configFile) Toml() toml.Document {
	if c == nil {
		return toml.Document{}
	}
	return c.doc
}
func (c *configFile) findAndReadTomlFile(name string) error {
	var err error
	if filepath.IsAbs(name) {
		fileInfo, err := os.Stat(name)
		if err == nil {
			if fileInfo.IsDir() {
				c.doc, err = c.readTomlFile(filepath.Join(name, appName()+".toml"))
			} else {
				c.doc, err = c.readTomlFile(name)
			}
			return err
		}
	}
	cfgPath := os.Getenv(strings.ToUpper(appName() + "_CFGPATH"))
	if len(cfgPath) > 0 {
		if len(name) > 0 {
			cfgPath = filepath.Join(cfgPath, name)
		}
		c.doc, err = c.readTomlFile(cfgPath)
		if err == nil {
			return nil
		}
	}
	cfgPath, _ = GetUserConfigDir()
	if len(cfgPath) > 0 {
		if len(name) == 0 {
			name = "config.toml"
		}
		path := filepath.Join(cfgPath, name)
		c.doc, err = c.readTomlFile(path)
		if err == nil {
			return nil
		}
	}
	cfgPath, err = os.Getwd()
	if err == nil {
		if len(name) == 0 {
			name = appName() + ".toml"
		}
		c.doc, _ = c.readTomlFile(filepath.Join(cfgPath, name))
		return nil
	}
	return err
}
func (c *configFile) readTomlFile(path string) (toml.Document, error) {
	var parser toml.Parser
	var err error
	emptyDoc := parser.Parse("")  
	if _, err = os.Stat(path); err == nil {
		c.path = path
		return parser.ParseFile(path), nil
	}
	return emptyDoc, err
}
func GetUserConfigDir() (dir string, exists bool) {
	if runtime.GOOS == "windows" {
		dir = filepath.Join(os.Getenv("LOCALAPPDATA"), appName())
	} else {
		dir = os.Getenv("XDG_CONFIG_HOME")
		if dir == "" {
			dir = filepath.Join(os.Getenv("HOME"), ".config", appName())
		}
	}
	exists = true
	_, err := os.Stat(dir)
	if os.IsNotExist(err) {
		exists = false
	}
	return dir, exists
}