Hi!
Im new to golang(a week or so), but have some experience in C++
Im trying to create some code that reads from a file that gets constantly written to.
Its should do that by writing the length of the textfile to a integer (the CountLogLines function)
next time it reads the file, it should save each individual new line in a slice of strings,
and then set the length again.
So that afterwards i can access the slice returned from the function and delimit every new line individually.
For some reason my code isnt working tho…
It either outputs nothing, or it skips lines.
Help?
Thanks
Textfile is written like this:
\n
\r \n
Some_String\n
\n
\r \n
Some_String\n
func countLogLines() int {
f, err := ioutil.ReadFile(logFileLocation)
if err != nil {
log.Fatalf("countLogLines: ioutil.ReadFile() Error: %v", err)
}
str := strings.Split(string(f), "\n")
return len(str)
}
func readLog() []string {
f, err := ioutil.ReadFile(logFileLocation)
if err != nil {
log.Fatalf("readLogFile: ioutil.ReadFile() Error: %v", err)
}
str := strings.Split(string(f), "\n")
if loglen < len(str) {
var strout []string
i := 1
for i+loglen <= len(str) {
strout = append(strout, str[i+loglen])
}
loglen = len(str)
return strout
}
return nil
}