Пример #1
0
//append one row
func AppendR(row string) {
	if strings.HasPrefix(row, "mode") {
		return
	}
	rvals := strings.Split(row, " ")
	if len(rvals) < 3 {
		log.W("invalid row:%s", row)
		return
	}
	a, err := strconv.Atoi(rvals[1])
	if err != nil {
		log.W("covert row(%v) error:%s ", row, err.Error())
		return
	}
	b, err := strconv.Atoi(rvals[2])
	if err != nil {
		log.W("covert row(%v) error:%s ", row, err.Error())
		return
	}
	if c, ok := cache[rvals[0]]; ok {
		if c.A < 1 {
			c.A = a
		}
		if c.B < 1 {
			c.B = b
		}
		cache[rvals[0]] = c
	} else {
		cache[rvals[0]] = Cover{A: a, B: b}
	}
}
Пример #2
0
//append file
func AppendF(fname string) {
	log.D("append file:%s", fname)
	f, err := os.Open(fname)
	if err != nil {
		log.W("open file(%v) error:%s", fname, err.Error())
		return
	}
	defer f.Close()
	buf := bufio.NewReader(f)
	for {
		l, err := util.ReadLine(buf, 102400, false)
		if err == io.EOF {
			break
		} else if err != nil {
			log.W("read file(%s) error:%s", fname, err.Error())
		} else {
			AppendR(string(l))
		}
	}
}
Пример #3
0
func walk_c(dir string, out string, path string, fi os.FileInfo, err error, exec func(path string) error) error {
	if err != nil {
		log.W("list path error(%v)", err.Error())
		return nil
	}
	if fi.IsDir() {
		return nil
	}
	if strings.HasPrefix(path, out) {
		return nil
	}
	return exec(path)
}