As mentioned in GoDocs, os.Create() creates a file in specific path.
os.Create("fonts/foo/font.eot")
But when fonts or foo doesn't exists, it returns panic: open fonts/foo/font.eot: The system cannot find the path specified.
So i used os.MkdirAll() to create nested directory. But there are many other problems with this function.
path := "fonts/foo/font.eot"
// this line create a directory named (font.eot) !
os.MkdirAll(path, os.ModePerm)
Is there any better way to create a file in nested directories?
mkdirandopensystem calls. What "many other problems" are you referring to?os.MkdirAll("fonts/foo", 0770); os.Create("fonts/foo/font.eot")Dead simple and totaly obvious.0777rather than0770here. File creation generally should use mode0666. These allow the user's umask to take away group and/or other write permissions if desired, or even more permissions (resulting in modes like 0750 or 0700 for a directory) if desired. (I've seen this advice to use 0770 elsewhere, but am not sure where it originates.)