I have a log file, and I need to parse each record in it using golang. Each record begin with "#", and a record can span one or more lines :
# Line1
# Line2
Continued line2
Continued line2
# line3
.....
Some code :), I'm a beginner
f, _ := os.Open(mylog)
scanner := bufio.NewScanner(f)
var queryRec string
for scanner.Scan() {
line := scanner.Text()
if strings.HasPrefix(line, "# ") && len(queryRec) == 0 {
queryRec = line
} else if !strings.HasPrefix(line, "# ") && len(queryRec) == 0 {
fmt.Println("There is a big problem!!!")
} else if !strings.HasPrefix(line, "# ") && len(queryRec) != 0 {
queryRec += line
} else if strings.HasPrefix(line, "# ") && len(queryRec) != 0 {
queryRec = line
}
}
Thanks,