Solution 4: Code Testing and Profiling
Let’s solve the challenge set in the previous lesson.
We'll cover the following
Solution
The os.TempDir()
method creates a temporary directory. The temporary directory is created at a path depending on the operating system used. On macOS, it is under /var/folders
; on Linux, it is under /tmp
; on Windows, it is under %TMP%
.
The following TempDir.go
code finds the value of os.TempDir()
in various operating systems using the Go language. Here, the code will print /tmp
because we are using Linux:
Get hands-on with 1400+ tech skills courses.