linstrom/Code-Style.md
2025-04-14 16:59:59 +02:00

1.3 KiB

Code style guide

Go

  • Use gofmt
  • jsonapi fields must use dasharised names (eg some-field instead of some_field or someField)
  • Function, struct and variable names must describe their purpose adequatly. Making them longer for that purpose is fine
  • Follow [https://go.dev/doc/effective_go] (which also happens to be convenient place to start learning Go)
  • Always use zerolog for console output. In http handlers, use hlog.FromRequest to get a logger instance prepared with a bunch of metadata
  • As Linstrom is both intended for active use as well as providing a learning resource, all functions and structs must be documented and follow the conventions on [https://tip.golang.org/doc/comment]
  • Errors returned from public functions must either be wrapped with git.mstar.dev/mstar/goutils/other.Error and given appropriate descriptive information or return an error defined (as public variable) in that package. Example: other.Error("auth", "failed to do something important", originalError)
  • Returned http errors must use git.mstar.dev/mstar/goutils/webutils.ProblemDetails(StatusOnly).
  • Every function must either have a test or a doc comment explaining why it doesn't have a test

JS/TS

  • Biome should do most of the work