re: Attempting to Learn Go - Sorting and Moving Files by Extension VIEW POST

FULL DISCUSSION
 

In prepAndMove you have quite some repetition. I would make a map of extension to document type:

jpg: image
png: image
txt: document
...

This way you can remove the duplicate code. Also your config would look cleaner (simple data vs scattered code) and could even be loaded in runtime from an external file.

 

Thanks for the comment! I kind of touched on that in the post. I have given myself an arbitrary time limit to get these posts up. It was looking like I may not hit it so I never went back and added it. The original plan was a map[string][]string with the document folder and then the array of extensions. As it is now, the switch wouldn't be that bad if I got rid of the repetitive error code as well.

code of conduct - report abuse