• 0 Posts
  • 2 Comments
Joined 1 year ago
cake
Cake day: June 17th, 2023

help-circle
  • 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 :)

    Also check out the docs for testing https://pkg.go.dev/testing should hopefully get you started