Esempio n. 1
0
func GetMapValues(path string) (*map[string]float64, error) {
	lines, err := FileToLines(path)
	ootest.Check(err)
	m := make(map[string]float64)
	for _, v := range lines {
		val, err := GetStringValue("[[", "]]", v)
		ootest.Check(err)
		intVal, err := strconv.ParseFloat(val, 64)
		ootest.Check(err)
		m[val] += intVal
	}
	return &m, nil
}
Esempio n. 2
0
func FileToLines(path string) ([]string, error) {
	file, err := os.Open(path)
	ootest.Check(err)
	defer file.Close()

	var lines []string
	scanner := bufio.NewScanner(file)
	for scanner.Scan() {
		lines = append(lines, scanner.Text())
	}
	return lines, scanner.Err()
}
Esempio n. 3
0
func main() {
	path := "testdata/logdata/test.log"
	lines, err := logparser.FileToLines(path)
	ootest.Check(err)
	ootest.CheckBool(lines[0] == string("message test 1 [[1234]]"))
	ootest.CheckStrings(lines[1], string("message test 2 [[12.34]]"))
	value, err := logparser.GetStringValue("[[", "]]", "Test Line [[1234]]")
	ootest.Check(err)
	ootest.CheckStrings(value, string("1234"))

	m, err := logparser.GetMapValues(path)
	expectedString := []string{"1234", "12.34"}
	expectedInt := []float64{1234, 12.34}
	var index = 0
	for key, value := range *m {
		ootest.CheckStrings(key, expectedString[index])
		ootest.CheckFloat64(value, expectedInt[index])
		index++
	}
	ootest.ExitSuccess()
}