Obtain a new temp file : tmpfile, err := ioutil.TempFile("", "")
Obtain a new temp dir : dir, err := ioutil.TempDir("", "") I suggest you don't bother with cleanup. It should work on any OS. On Friday, November 18, 2016 at 11:21:23 AM UTC+1, Ondrej wrote: > > I have a tool that generates some HTML and launches a web browser to > display it. For this to work, I need to save the HTML some place and I also > need to handle the file afterwards. The app itself doesn't persist - it > generates the content and exits. There are thus two issues I'm struggling > with: > > 1. What is the best place for this? Do I create a folder in > usr.HomeDir()/.appname/ and place HTML files there? Or do I just create > tempfiles in os.TempDir? Does it make a difference? > 2. How do I clean up? As I said, the app does not persist (so I can't > defer os.Remove), so either I scan the folder in question (before my HTML > generation) and remove all files older than, say, a day. Or is that done > for me by the operating system if I use os.TempDir? > > I thought I'd just use os.TempDir and let the OS handle it, but I'm not > 100% sure the OS does clean this up on its own. (This will be used on > Windows and Macs, maybe Linux.) Any insight on any of these would be > greatly appreciated. > > Thanks! > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.