I'm trying to pop the first line of a file and thus reduce the file lines one by one. My implementation for removing the first line is as follows
type FS struct {
...
File *os.File
}
//File creation ok...
func (fs *Fs) pop() []byte {
var buf []string
scanner := bufio.NewScanner(fs.File)
//Reading lines
for scanner.Scan() {
line := scanner.Text()
buf = append(buf, line)
}
//Writing from second line on the same file
for s := 1; s < len(buf); s++ {
fs.File.WriteString(fmt.Println(buf[s]))
}
//Commit changes
fs.File.Sync()
fs.File.Close()
return []byte(buf[0])
}
I get the returned []byte with the expected string but the file never changes. What am I missing here?
For example,