Пример #1
0
func Read(dir string) Items {
	items := make(map[string][][]string)
	// each settings
	for key, se := range settings {
		if pa := path.Join(dir, key); util.Exists(pa) {
			its := [][]string{}
			// each lines of file
			for line, str := range util.ReadFile(pa) {
				// if succeeded reading
				if it := se.read(str); len(it) != 0 {
					its = append(its, it)
				} else {
					util.PrintErrorMessage(util.FormatErrorAtLine(pa, line, "Can't parse"))
				}
			}
			if len(its) > 0 {
				items[key] = its
			}
		}
	}
	pa := path.Join(dir, RC)
	// each lines of file
	for line, str := range util.ReadFile(pa) {
		read := false
		if fir := strings.Index(str, " "); fir != -1 {
			key := str[:fir]
			str := str[fir+1:]
			// if setting exists
			if se, ok := settings[key]; ok {
				// if succeeded reading
				if it := se.read(str); len(it) != 0 {
					is, ok := items[key]
					if !ok {
						is = [][]string{}
					}
					items[key] = append(is, it)
					read = true
				}
			}
		}
		if !read {
			util.PrintErrorMessage(util.FormatErrorAtLine(pa, line, "Can't parse"))
		}
	}
	return Items(items)
}
Пример #2
0
Файл: io.go Проект: ryo33/zenv
//Exists local environment
func ExistsLocalEnv(name string) bool {
	if util.Exists(getLocalPath(name)) {
		return true
	}
	return false
}
Пример #3
0
func updateLast(key string) {
	if util.Exists(GetStorageDir(TMP, key)) {
		util.WriteFile(getStorageFilePath(TMP, key, LAST), []string{Now()})
	}
}