Esempio n. 1
0
// WriteData
func WriteData(location string, data [][]string) error {
	if location == "" {
		location = "/rundata/export.csv"
	}
	content := BuildCsvContent(data)
	_, err := mcore.WriteFile(location, content)
	logger.Debug("Write CSV data to :", location, ", Result: ", err)
	return err
}
Esempio n. 2
0
func (c *AppConf) Init() {
	if c.IsExist() {
		return
	}
	sb := mcore.NewStringBuffer()
	sb.AppendLine("# Auto Generate")
	sb.AppendLine(fmt.Sprintf("%s=%s", KEY_VENDOR_NAME, V_VENDOR_MABETLE))
	logger.Tracef("Init config. AppName:%s Location:%s", c.AppName, c.Location())
	_, err := mcore.WriteFile(c.Location(), sb.String())
	if err != nil {
		logger.Error(err)
	}
}
Esempio n. 3
0
File: main.go Progetto: mabetle/mcmd
func fileReplace(item, searchStr, replaceStr string) {
	text, err := mcore.ReadFileAll(item)
	// cannot read file
	if nil != err {
		fmt.Printf("Read file error: %v\n", err)
		return
	}
	if !strings.Contains(text, searchStr) {
		return
	}
	nums := strings.Count(text, searchStr)
	fmt.Printf("File: %s found %d matches.\n", item, nums)
	//do replace
	text = strings.Replace(text, searchStr, replaceStr, -1)
	if _, err := mcore.WriteFile(item, text); err != nil {
		fmt.Printf("Write file %s \n Error: %v", item, err)
	} else {
		fmt.Println("Write file :", item)
	}
}