示例#1
0
文件: utils.go 项目: jmptrader/spirit
func loadConfig(fileName string, v interface{}) (strMD5 string, err error) {
	envJson := env_json.NewEnvJson(ENV_NAME, ENV_EXT)

	var data []byte
	if data, err = ioutil.ReadFile(fileName); err != nil {
		return
	}

	if err = envJson.Unmarshal(data, v); err != nil {
		return
	}

	//make sure the md5 genreate from same struct
	ops := Options{}
	if err = envJson.Unmarshal(data, &ops); err != nil {
		return
	}

	if data, err = envJson.Marshal(ops); err != nil {
		return
	}

	md5Data := md5.Sum(data)

	strMD5 = fmt.Sprintf("%0x", md5Data)

	return
}
示例#2
0
文件: main.go 项目: gogap/spirit-tool
func main() {
	var err error
	defer func() {
		if err != nil {
			spirit.Logger().Error(err)
			os.Exit(128)
		}
	}()

	if configFile != "" {
		var fileData []byte
		if fileData, err = ioutil.ReadFile(configFile); err != nil {
			return
		}

		config = string(fileData)
	}

	if config == "" {
		err = fmt.Errorf("config is empty")
		return
	}

	spiritConf := spirit.SpiritConfig{}

	if envJsonKey != "" && os.Getenv(envJsonKey) != "" {
		envJson := env_json.NewEnvJson(envJsonKey, envJsonExt)
		if err = envJson.Unmarshal([]byte(config), &spiritConf); err != nil {
			return
		}
	} else {
		if err = json.Unmarshal([]byte(config), &spiritConf); err != nil {
			return
		}
	}

	if err = spiritConf.Validate(); err != nil {
		err = fmt.Errorf("spirit config validate failed, %s", err)
		return
	}

	var sp spirit.Spirit
	if sp, err = spirit.NewClassicSpirit(); err != nil {
		err = fmt.Errorf("create new classic spirit error, %s", err)
		return
	}

	if err = sp.Build(spiritConf); err != nil {
		err = fmt.Errorf("build classic spirit error, %s", err)
		return
	}

	var wg *sync.WaitGroup
	if wg, err = sp.Run(); err != nil {
		return
	}

	wg.Wait()
}
示例#3
0
func LoadLogrusMateConfig(filename string) (conf LogrusMateConfig, err error) {
	var data []byte

	if data, err = ioutil.ReadFile(filename); err != nil {
		return
	}

	envJSON := env_json.NewEnvJson(env_json.ENV_JSON_KEY, env_json.ENV_JSON_EXT)

	if err = envJSON.Unmarshal(data, &conf); err != nil {
		return
	}

	return
}