Exercise: Defer remove temporary directory


Write a function that will create a temporary directory and then it will remove it once the function is done. Make sure the directory is removed no matter how you exit from the function.


examples/remove-temp-directory/remove_temp_directory.go
package main

import "fmt"

func main() {
    doSomething()

}

func doSomething() {
    dir := createTempDir()

    //defer removeTempDir(dir)

    if true {
        removeTempDir(dir)
        return
    }

    removeTempDir(dir)
}

func createTempDir() string {
    return "some/path"
}

func removeTempDir(dir string) {
    fmt.Printf("")
}