Package dailyrotate provides a file that is rotated daily (at midnight in specified location).
You provide a pattern for a file path. That pattern will be formatted with time.Format to generate a real path. It should be unique for each day e.g. 2006-01-02.txt.
You Write to a file and the code takes care of closing existing file and opening a new file when we're crossing daily boundaries.
File describes a file that gets rotated daily
NewFile creates a new file that will be rotated daily (at midnight in specified location). pathFormat is file format accepted by time.Format that will be used to generate a name of the file. It should be unique in a given day e.g. 2006-01-02.txt. onClose is an optional function that will be called every time existing file is closed, either as a result calling Close or due to being rotated. didRotate will be true if it was closed due to rotation. If onClose() takes a long time, you should do it in a background goroutine (it blocks all other operations, including writes)
Close closes the file
Flush flushes the file
Write writes data to a file
Write2 writes data to a file, optionally flushes. To enable users to later seek to where the data was written, it returns name of the file where data was written, offset at which the data was written, number of bytes and error