DEV Community

Creating custom directories and files for your Flutter project with Go

Adetoba ✨ on August 20, 2023

As a flutter developer, it can be really cumbersome having to create directories and files for your project all the time 😓. Every flutter project, ...
Collapse
 
mokiat profile image
Momchil Atanasov • Edited

I'd like to offer some feedback.

  1. Your concatenation fmt.Sprintf("/%v/%v"... produces absolute paths starting at root. It probably works right now just because os.Args[1] returns an absolute path. But if a relative path is provided I believe that the code will not work as intended.

  2. Actually avoid using fmt.Sprintf to join paths to begin with. Even if you remove the leading / character, the produced path would work only on Unix platforms and not always. The correct approach is to use filepath.Join. This takes the OS into consideration and on Windows it would use \ instead of /. Additionally it does some cleaning up of the path but you can check the details in the godoc. You would need to use the same in your map initialization as well or you can use os.PathSeparator instead of / or you could give filepath.FromSlash a try.

  3. You can consider using log.Print* instead of fmt.Print. This one is a bit nit picking but there is a difference worth mentioning, which might not be relevant in your particular case.

    The log package outputs to stderr, whereas fmt outputs to stdout. And the general pattern for UNIX tools is for a CLI/tool to output info logs to stderr and content to stdout. That way tools can be piped and the stdout content would be passed to the subsequent tool, whereas the stderr logs would be printed for debugging purposes. Now, in your case you won't really be piping your tool's output, so this might not be worthwhile.

Collapse
 
tobacodes profile image
Adetoba ✨

Thanks for the feedback. Very appreciated 🤙

Collapse
 
tobacodes profile image
Adetoba ✨

Would you be open to connect? I would love to have some discussions with you about go.