Format

Sorting Imports Canonical CF02110

Packages can be divided in to three types, standard library, our own packages, and third party packages.

Imports should be grouped accordingly, with the standard library packages first, followed by packages starting with github.com/cirruscomms/ and then third party packages.

Examples
package main

import (
	"context"
	"flag"
	"fmt"
	"net/http"

	"github.com/cirruscomms/go-common/pkg/db/migrations"
	"github.com/cirruscomms/go-common/pkg/env/config"
	"github.com/cirruscomms/go-logging"
	etc "github.com/cirruscomms/optus-service/etc/migrations"
	"github.com/cirruscomms/optus-service/internal/api"
	"github.com/cirruscomms/optus-service/internal/api/base"
	"github.com/cirruscomms/optus-service/internal/optus"
	actions "github.com/cirruscomms/optus-service/internal/optusActions"

	"github.com/joho/godotenv"
	"github.com/sirupsen/logrus"
)
IDE Configuration

This can be achieved auto-magically by configuring your IDE and/or Go’s language server to use gofumpts as the formatter for Go files.

For VS Code with formatting handled by gopls the settings are:

{
    "gopls": {
        "analyses": {
            "nilness": true,
            "shadow": false,
            "unusedvariable": true,
            "useany": true,
        },
        "codelenses": {
            "run_govulncheck": false
        },
        "formatting.gofumpt": true,
        "formatting.local": "github.com/cirruscomms/",
        "staticcheck": true,
        "ui.semanticTokens": true
    },
}

Renaming Imports Normative CF02120

Naming Packages Normative CF02210

Package names should be camelCase, with the exception of _test packages, which should just be camelCase package names with the _test suffix appended to them.

Examples
package simple // okay
package simpleBrands // okay
package simpleBrands_test // okay

package simple_brands // not okay
package simplebrands // not okay

Naming Types Proposed CF02215

Naming Constants Proposed CF02220

Naming Variables Proposed CF02225

Naming Interfaces Proposed CF02230

Naming Mock Structs Proposed CF02235

Naming Functions Proposed CF02240

Naming Methods Proposed CF02245

Initialisms - Never Mixed Case Proposed CF02250

Initialisms should be written either in all upper or all lower case, never mixed.

Examples
var nbnClient = "all lower case" // okay
var NBNClient = "all upper clase" // okay
var NbnClient = "all upper clase" // not okay

Initialisms - ID vs Id Proposed CF02251

ID is an initialism for Identity Document - this is used to refer to driver’s licences, passports, birth certificates, etc.

Id is ann abbreviation for Identifier - this is used to refer to index integers and universally/globally unique identifiers.

Both these terms can be pronounced Eye-Dee.

Ordering Struct Fields Idiomatic CF02270

Naming Struct Fields Proposed CF02275

Ordering Struct Tags Proposed CF02280

Naming Struct Tags - Env Normative CF02285

Naming Struct Tags - JSON Normative CF02290

GoDoc Package Comments Canonical CF02310

GoDoc Package Examples Canonical CF02312

GoDoc Function Comments Canonical CF02314

GoDoc Function Examples Canonical CF02316

Comments Explain Why, Not What Canonical CF02320

Inner Function Heading Comments Canonical CF02330

Functions & Methods - Contract Parameters Normative CF02410

Functions & Methods - Contract Return Normative CF02420

Functions & Methods - Ordering Contract Returns Normative CF02430

Functions & Methods - Naked Return Statements Normative CF02440

API - Routes Normative CF02510

API - Methods Normative CF02520

API - Status Codes Normative CF02530