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
},
}