I have rotated files, and I need change files periodically, but I can't renew my pointer to file
var (
file *os.File
)
func init() {
file, err = os.Create(fileName)
}
func main() {
ticker = time.NewTicker(time.Second * 6)
defer ticker.Stop()
go func(file *os.File) {
<- ticker.C
fn := fmt.Sprintf("%d%s", time.Now().Unix(), ".txt")
file, _ = os.Create(fn)
}(file)
http.HandleFunc("/go", goHandler)
}
func goHandler(w http.ResponseWriter, r *http.Request) {
fmt.Printf("hand File: %v
", *file)
// when handler triggered file stay the same
file.WriteString(myPayload)
}
it changes inside goroutines, but it doesn't react in handler, so the file stays the same all time.
Suggest, pls, how I can change pointer to *os.File