func AppendToFile(content string) {
filePath := "static/index.html"
file, err := os.OpenFile(filePath, os.O_WRONLY | os.O_APPEND, 0666)
if err != nil {
fmt.Printf("open file error=%v\n", err)
return
}
defer file.Close()
writer := bufio.NewWriter(file )
writer.WriteString(content +"<br/>")
writer.Flush()
}
go 追加内容到文件
2 min read