February 2018
Intermediate to advanced
340 pages
9h 43m
English
package main import ( "fmt" "io" "log" "os" "os/signal" "syscall" "time" ) var writer *os.File func main() { // The file is opened as // a log file to write into. // This way we represent the resources // allocation. var err error writer, err = os.OpenFile(fmt.Sprintf("test_%d.log", time.Now().Unix()), os.O_RDWR|os.O_CREATE, os.ModePerm) if err != nil { panic(err) } // The code is running in a goroutine // independently. So in case the program is // terminated from outside, we need to // let the goroutine know via the closeChan closeChan := make(chan bool) go func() { for { time.Sleep(time.Second) ...Read now
Unlock full access