Feedback for my first project: reimplement pulp-manifest in go
Hi đź‘‹
I have tried to learn some go but I am still very much at the beginning, like understanding how to work with variables and functions. My background is mostly in python but I am not a programmer by trade.
I am testing this using the following command: rm -f test_input/PULP_MANIFEST && go fmt pulp_manifest.go && go build pulp_manifest.go && ./pulp_manifest test_input && cat test_input/PULP_MANIFEST on Fedora with go 1.20
Known Limitations
My rewrite does not handle files or directories with "," yet.
Untested
Files with binary content
Paths on macOS or Microsoft Windows
Paths with whitespace
Symlinks in target_directory
target_directory as symlink
I am looking for the following feedback:
bugs and limitations
a was to add tests: do you have any recommendations for talks or blog posts?
style & best practice
a way to use static typing?!
anything else that you would recommend a novice.
Right now, I believe my rewrite works. Feel free to shatter my assumption. Cheers.
Haven’t copied it yet to an editor so just a few things:
naming convention in Go is camelCase not snake_case
prefer to accept io.Reader over opening files in every function. Improves testability but also is best practice
return errors whenever possible instead of just logging them or do something about if you can (like creating a file if it doesn’t exist yet if it makes sense) - don’t use panic if you don’t have to! Panics are only a last resort if there’s no way to handle the error gracefully, think: compile a regex as a global variable that you need and that’s static, the expression won’t change magically so there’s no way the program can continue without a valid expression
move logic to some package (== sub-directory with a package name != main) and have at least one function with a PascalCase name to call from you main package. Functions starting with a capital letter are public whereas functions starting with a lowercase letter are private - not by convention but enforced by the compiler!
For a more thorough review I’ve to get to a computer but probably someone else has some more tips for you :)