示例#1
0
文件: Env.go 项目: iizotop/kmg
func FindFromPath(p string) (context *Env, err error) {
	p, err = filepath.Abs(p)
	if err != nil {
		return
	}
	var kmgFilePath string
	for {
		kmgFilePath = filepath.Join(p, ".kmg.yml")
		_, err = os.Stat(kmgFilePath)
		if err == nil {
			//found it
			break
		}
		if !os.IsNotExist(err) {
			return
		}
		thisP := filepath.Dir(p)
		if p == thisP {
			err = NotFoundError{}
			return
		}
		p = thisP
	}
	context = &Env{}
	err = kmgYaml.ReadFile(kmgFilePath, context)
	if err != nil {
		return
	}
	context.ProjectPath, err = filepath.Abs(filepath.Dir(kmgFilePath))
	if err != nil {
		return
	}
	context.Init()
	return
}
示例#2
0
文件: DbConfig.go 项目: keysonZZZ/kmg
func mustLoadConfigByFilename(filename string) {
	conf := TestDbConf{}
	err := kmgYaml.ReadFile(kmgConfig.DefaultEnv().PathInConfig(filename), &conf)
	if err != nil {
		panic(err)
	}
	SetDefaultDbConfig(conf.Db)
}
示例#3
0
文件: init.go 项目: iizotop/kmg
func init() {
	Parameter = &kmgConfig.Parameter{}
	path := filepath.Join(defaultEnv.Env.ConfigPath, "parameters.yml")
	err := kmgYaml.ReadFile(path, Parameter)
	if err != nil {
		panic(fmt.Errorf("can not get Parameters config,do you forget write a config file at %s ? err: %s", path, err))
	}
}
示例#4
0
// @deprecated
func DefaultParameter() *Parameter {
	parameterOnce.Do(func() {
		parameter = &Parameter{}
		path := filepath.Join(DefaultEnv().ConfigPath, "Parameters.yml")
		err := kmgYaml.ReadFile(path, parameter)
		if err != nil {
			panic(fmt.Errorf("can not get Parameters config,do you forget write a config file at %s ? err: %s", path, err))
		}
	})
	return parameter
}
示例#5
0
文件: Env.go 项目: keysonZZZ/kmg
func FindFromPath(p string) (context *Env, err error) {
	p, err = kmgFile.SearchFileInParentDir(p, ".kmg.yml")
	if err != nil {
		return
	}
	kmgFilePath := filepath.Join(p, ".kmg.yml")
	context = &Env{}
	err = kmgYaml.ReadFile(kmgFilePath, context)
	if err != nil {
		return
	}
	context.ProjectPath, err = filepath.Abs(filepath.Dir(kmgFilePath))
	if err != nil {
		return
	}
	context.Init()
	return
}