Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 7 Current »

These guidelines for writing Go code are WIP


This document covers common coding styles and guidelines for all ForgeRock products.

Copyright notices

Within the FRaaS codebases we are not currently adding licence headers to individual source files.  This practice diverges from the standard practice of doing so across other projects.

The ForgeRock Go coding style


  • Each Go project should include one or more files detailing
    • An overview of the project and its purpose
    • How to build, test, deploy and configure the executable
  • All public constants, structs, fields, interfaces and functions must have Go doc
  • All packages must have Go doc - Packages with more than one source file should consider providing package documentation using a doc.go file

Source code layout

In addition to good documentation, having a consistent approach to organising code across directories and within a given source file makes it easier for engineers to move between projects and get up to speed quickly.

  • Each Go project should use a standard layout
  • Each Go source file should, as far as possible, be readable top-to-bottom with public / high level functions at the top of source files and private / helper functions lower down:
    • vars/consts
    • interfaces
    • structs
    • methods
    • constructors
    • public functions
    • private functions

Linting rules

Where possible, agreed standards relating to source files should be enforced by linting during continuous integration.  The linting rules currently in use by the FRaaS team are:

  # inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
  disable-all: true
    - deadcode
    - errcheck
    - gofmt
    - goimports
    - gosimple
    - govet
    - ineffassign
    - structcheck
    - typecheck
    - unused
    - varcheck

  tests: true


  • Prefer to avoid logging directly at the site where an error is returned.  Instead, use errors.Wrap to add context to the returned error and let the entry point to processing decide if and how these errors should be logged.

Idiomatic Go

In addition to the points raised above, we should endeavour to write idiomatic Go.  Guidance for what these idioms are and how to follow them can be found in:

  • No labels