January 2018
Intermediate to advanced
340 pages
8h 6m
English
The ioutil package provides two functions: TempDir() and TempFile(). It is the caller's responsibility to delete the temporary items when done. The only benefit these functions provide is that you can pass it an empty string for the directory, and it will automatically create the item in the system's default temporary folder (/tmp on Linux), since the os.TempDir() function will return the default system temporary directory:
package main import ( "fmt" "io/ioutil" "log" "os" ) func main() { // Create a temp dir in the system default temp folder tempDirPath, err := ioutil.TempDir("", "myTempDir") if err != nil { log.Fatal(err) } fmt.Println("Temp dir created:", tempDirPath) // Create a file in new temp ...Read now
Unlock full access