Created
June 30, 2018 10:38
-
-
Save miguelmota/d065806656c81021527069f3877fa762 to your computer and use it in GitHub Desktop.
Golang create temporary directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"io/ioutil" | |
"log" | |
) | |
func main() { | |
tmp, err := ioutil.TempDir("", "") | |
if err != nil { | |
log.Fatal(err) | |
} | |
fmt.Println(tmp) // /var/folders/k1/m2rmftgd48q97pj0xf9csdb00000gn/T/254614131 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In case someone else lands here searching for this: as of Go 1.17
ioutil.TempDir()
is deprecated in favour ofos.MkdirTemp()
(same arguments, same behaviour, drop-in replacement).