diff --git a/.golangci.json b/.golangci.json index 6fcef07..1100652 100644 --- a/.golangci.json +++ b/.golangci.json @@ -51,6 +51,18 @@ "golines" ], "settings": { + "gci": { + "sections": [ + "standard", + "default", + "localmodule" + ] + }, + "goimports": { + "local-prefixes": [ + "git.avsdev.uk/Go/job-search" + ] + }, "golines": { "max-len": 100, "tab-len": 2 diff --git a/cmd/jobsearch/main.go b/cmd/jobsearch/main.go index adc5949..d8d9fba 100644 --- a/cmd/jobsearch/main.go +++ b/cmd/jobsearch/main.go @@ -23,13 +23,14 @@ import ( "os" "strings" + "github.com/spf13/cobra" + "git.avsdev.uk/Go/job-search/internal/cli" "git.avsdev.uk/Go/job-search/internal/cli/config" "git.avsdev.uk/Go/job-search/internal/cli/fetch" "git.avsdev.uk/Go/job-search/internal/cli/migrate" "git.avsdev.uk/Go/job-search/internal/cli/version" "git.avsdev.uk/Go/job-search/internal/cli/wsserve" - "github.com/spf13/cobra" ) // newRootCmd builds the command tree. It returns a fresh tree on each call so diff --git a/cmd/mock-fts/main.go b/cmd/mock-fts/main.go index 0f64f58..9711fd0 100644 --- a/cmd/mock-fts/main.go +++ b/cmd/mock-fts/main.go @@ -32,9 +32,10 @@ import ( "time" _ "time/tzdata" + "github.com/spf13/cobra" + "git.avsdev.uk/Go/job-search/internal/logging" mock "git.avsdev.uk/Go/job-search/internal/mock/findatender" - "github.com/spf13/cobra" ) // options holds the values of every command-line flag. diff --git a/internal/cli/cli_test.go b/internal/cli/cli_test.go index 96db38b..95ad006 100644 --- a/internal/cli/cli_test.go +++ b/internal/cli/cli_test.go @@ -7,9 +7,10 @@ import ( "strings" "testing" - "git.avsdev.uk/Go/job-search/internal/logging" "github.com/spf13/cobra" "github.com/spf13/viper" + + "git.avsdev.uk/Go/job-search/internal/logging" ) // The commands themselves are tested through the real command tree in diff --git a/internal/cli/cmdtest/cmdtest.go b/internal/cli/cmdtest/cmdtest.go index 1838590..a3814e9 100644 --- a/internal/cli/cmdtest/cmdtest.go +++ b/internal/cli/cmdtest/cmdtest.go @@ -14,10 +14,11 @@ import ( "strings" "testing" - "git.avsdev.uk/Go/job-search/internal/cli" - "git.avsdev.uk/Go/job-search/internal/logging" "github.com/spf13/cobra" "github.com/spf13/viper" + + "git.avsdev.uk/Go/job-search/internal/cli" + "git.avsdev.uk/Go/job-search/internal/logging" ) // Setup changes into a new temporary directory holding an empty .env and, diff --git a/internal/cli/config/command.go b/internal/cli/config/command.go index bc2dda2..196535d 100644 --- a/internal/cli/config/command.go +++ b/internal/cli/config/command.go @@ -3,8 +3,9 @@ package config import ( "log/slog" - "git.avsdev.uk/Go/job-search/internal/cli" "github.com/spf13/cobra" + + "git.avsdev.uk/Go/job-search/internal/cli" ) // NewCommand returns the "config" command, which shows and edits the configuration. diff --git a/internal/cli/config/config_test.go b/internal/cli/config/config_test.go index 64ce7ec..32ea395 100644 --- a/internal/cli/config/config_test.go +++ b/internal/cli/config/config_test.go @@ -4,10 +4,11 @@ import ( "strings" "testing" - "git.avsdev.uk/Go/job-search/internal/cli" - "git.avsdev.uk/Go/job-search/internal/cli/cmdtest" "github.com/spf13/cobra" "go.yaml.in/yaml/v3" + + "git.avsdev.uk/Go/job-search/internal/cli" + "git.avsdev.uk/Go/job-search/internal/cli/cmdtest" ) // These tests run the config commands as a user would, through a root diff --git a/internal/cli/config/get.go b/internal/cli/config/get.go index 0b74d4e..79efe3f 100644 --- a/internal/cli/config/get.go +++ b/internal/cli/config/get.go @@ -4,8 +4,9 @@ import ( "fmt" "log/slog" - "git.avsdev.uk/Go/job-search/internal/cli" "github.com/spf13/cobra" + + "git.avsdev.uk/Go/job-search/internal/cli" ) func commandGet(opts *cli.Options) *cobra.Command { diff --git a/internal/cli/config/init.go b/internal/cli/config/init.go index c27bf9c..7bbd112 100644 --- a/internal/cli/config/init.go +++ b/internal/cli/config/init.go @@ -7,9 +7,10 @@ import ( "os" "strings" - "git.avsdev.uk/Go/job-search/internal/config" "github.com/spf13/cobra" "github.com/spf13/viper" + + "git.avsdev.uk/Go/job-search/internal/config" ) func commandInit() *cobra.Command { diff --git a/internal/cli/config/set.go b/internal/cli/config/set.go index 3a9dafc..66e1bfd 100644 --- a/internal/cli/config/set.go +++ b/internal/cli/config/set.go @@ -5,10 +5,11 @@ import ( "fmt" "log/slog" - "git.avsdev.uk/Go/job-search/internal/cli" - "git.avsdev.uk/Go/job-search/internal/config" "github.com/spf13/cobra" "github.com/spf13/viper" + + "git.avsdev.uk/Go/job-search/internal/cli" + "git.avsdev.uk/Go/job-search/internal/config" ) func commandSet(opts *cli.Options) *cobra.Command { diff --git a/internal/cli/config/show.go b/internal/cli/config/show.go index adbec17..a493f4a 100644 --- a/internal/cli/config/show.go +++ b/internal/cli/config/show.go @@ -4,8 +4,9 @@ import ( "fmt" "log/slog" - "git.avsdev.uk/Go/job-search/internal/cli" "github.com/spf13/cobra" + + "git.avsdev.uk/Go/job-search/internal/cli" ) func commandShow(opts *cli.Options) *cobra.Command { diff --git a/internal/cli/fetch/command.go b/internal/cli/fetch/command.go index 0cb6347..bdf4a10 100644 --- a/internal/cli/fetch/command.go +++ b/internal/cli/fetch/command.go @@ -3,8 +3,9 @@ package fetch import ( "log/slog" - "git.avsdev.uk/Go/job-search/internal/cli" "github.com/spf13/cobra" + + "git.avsdev.uk/Go/job-search/internal/cli" ) // NewCommand returns the "fetch" command, which fetches opportunities once or as a service. diff --git a/internal/cli/fetch/once.go b/internal/cli/fetch/once.go index 18660d4..843ad76 100644 --- a/internal/cli/fetch/once.go +++ b/internal/cli/fetch/once.go @@ -7,10 +7,11 @@ import ( "slices" "time" + "github.com/spf13/cobra" + "git.avsdev.uk/Go/job-search/internal/cli" "git.avsdev.uk/Go/job-search/internal/findatender" "git.avsdev.uk/Go/job-search/internal/types" - "github.com/spf13/cobra" ) // Release tags for each stage of a procedure, from the OCDS releaseTag diff --git a/internal/cli/fetch/service.go b/internal/cli/fetch/service.go index 07a50a5..92ddba6 100644 --- a/internal/cli/fetch/service.go +++ b/internal/cli/fetch/service.go @@ -9,9 +9,10 @@ import ( "syscall" "time" + "github.com/spf13/cobra" + "git.avsdev.uk/Go/job-search/internal/cli" "git.avsdev.uk/Go/job-search/internal/fetcher" - "github.com/spf13/cobra" ) func commandService(opts *cli.Options) *cobra.Command { diff --git a/internal/cli/flags_test.go b/internal/cli/flags_test.go index 6ded695..3a69eac 100644 --- a/internal/cli/flags_test.go +++ b/internal/cli/flags_test.go @@ -5,9 +5,10 @@ import ( "os" "testing" + "github.com/spf13/cobra" + "git.avsdev.uk/Go/job-search/internal/cli" "git.avsdev.uk/Go/job-search/internal/cli/cmdtest" - "github.com/spf13/cobra" ) // The shared flags (--config, --debug and --quiet), run through a root diff --git a/internal/cli/logging.go b/internal/cli/logging.go index eec1dde..f46f4b2 100644 --- a/internal/cli/logging.go +++ b/internal/cli/logging.go @@ -3,8 +3,9 @@ package cli import ( "log/slog" - "git.avsdev.uk/Go/job-search/internal/logging" "github.com/spf13/cobra" + + "git.avsdev.uk/Go/job-search/internal/logging" ) // SetupInitialLogging starts logging to the terminal, at the level set by diff --git a/internal/cli/migrate/common.go b/internal/cli/migrate/common.go index 7e7ce65..ec58df0 100644 --- a/internal/cli/migrate/common.go +++ b/internal/cli/migrate/common.go @@ -10,10 +10,11 @@ import ( "path/filepath" "time" - "git.avsdev.uk/Go/job-search/internal/cli" - "git.avsdev.uk/Go/job-search/internal/store" "github.com/pressly/goose/v3" "github.com/spf13/cobra" + + "git.avsdev.uk/Go/job-search/internal/cli" + "git.avsdev.uk/Go/job-search/internal/store" ) // openMigrator loads the configuration and returns a migrator over the diff --git a/internal/cli/migrate/down.go b/internal/cli/migrate/down.go index 9fedb6a..b27a7bb 100644 --- a/internal/cli/migrate/down.go +++ b/internal/cli/migrate/down.go @@ -5,9 +5,10 @@ import ( "fmt" "log/slog" + "github.com/spf13/cobra" + "git.avsdev.uk/Go/job-search/internal/cli" "git.avsdev.uk/Go/job-search/internal/store" - "github.com/spf13/cobra" ) func commandDown(opts *cli.Options) *cobra.Command { diff --git a/internal/cli/migrate/migrate.go b/internal/cli/migrate/migrate.go index 4bf1122..7ee67b9 100644 --- a/internal/cli/migrate/migrate.go +++ b/internal/cli/migrate/migrate.go @@ -9,8 +9,9 @@ package migrate import ( "log/slog" - "git.avsdev.uk/Go/job-search/internal/cli" "github.com/spf13/cobra" + + "git.avsdev.uk/Go/job-search/internal/cli" ) // NewCommand returns the "migrate" command, which migrates the database schema (see diff --git a/internal/cli/migrate/migrate_test.go b/internal/cli/migrate/migrate_test.go index 0366423..e4053a2 100644 --- a/internal/cli/migrate/migrate_test.go +++ b/internal/cli/migrate/migrate_test.go @@ -5,10 +5,11 @@ import ( "path/filepath" "testing" + "github.com/spf13/cobra" + "git.avsdev.uk/Go/job-search/internal/cli" "git.avsdev.uk/Go/job-search/internal/cli/cmdtest" "git.avsdev.uk/Go/job-search/internal/store" - "github.com/spf13/cobra" ) // Run with: go test -tags sqlite_fts5 ./... diff --git a/internal/cli/migrate/status.go b/internal/cli/migrate/status.go index e3270f4..bca7de7 100644 --- a/internal/cli/migrate/status.go +++ b/internal/cli/migrate/status.go @@ -8,10 +8,11 @@ import ( "path/filepath" "text/tabwriter" - "git.avsdev.uk/Go/job-search/internal/cli" - "git.avsdev.uk/Go/job-search/internal/store" "github.com/pressly/goose/v3" "github.com/spf13/cobra" + + "git.avsdev.uk/Go/job-search/internal/cli" + "git.avsdev.uk/Go/job-search/internal/store" ) // printStatus lists every migration as applied (with when) or pending, diff --git a/internal/cli/migrate/up.go b/internal/cli/migrate/up.go index d688bfc..266c8ac 100644 --- a/internal/cli/migrate/up.go +++ b/internal/cli/migrate/up.go @@ -4,9 +4,10 @@ import ( "fmt" "log/slog" + "github.com/spf13/cobra" + "git.avsdev.uk/Go/job-search/internal/cli" "git.avsdev.uk/Go/job-search/internal/store" - "github.com/spf13/cobra" ) // runStepUp applies steps pending migrations (0 means all), printing each one diff --git a/internal/cli/options.go b/internal/cli/options.go index a942acf..f52d05f 100644 --- a/internal/cli/options.go +++ b/internal/cli/options.go @@ -4,9 +4,10 @@ import ( "fmt" "log/slog" + "github.com/spf13/cobra" + "git.avsdev.uk/Go/job-search/internal/config" "git.avsdev.uk/Go/job-search/internal/logging" - "github.com/spf13/cobra" ) // Options holds the flags shared by every command. Bind registers them on the diff --git a/internal/cli/version/command.go b/internal/cli/version/command.go index 26e2e40..b88aded 100644 --- a/internal/cli/version/command.go +++ b/internal/cli/version/command.go @@ -4,8 +4,9 @@ import ( "fmt" "log/slog" - "git.avsdev.uk/Go/job-search/internal/version" "github.com/spf13/cobra" + + "git.avsdev.uk/Go/job-search/internal/version" ) // NewCommand returns the "version" command. diff --git a/internal/cli/wsserve/command.go b/internal/cli/wsserve/command.go index f126815..2654a5d 100644 --- a/internal/cli/wsserve/command.go +++ b/internal/cli/wsserve/command.go @@ -10,10 +10,11 @@ import ( "strings" "syscall" + "github.com/spf13/cobra" + "git.avsdev.uk/Go/job-search/internal/cli" "git.avsdev.uk/Go/job-search/internal/websocket" "git.avsdev.uk/Go/job-search/internal/websocket/tcpserver" - "github.com/spf13/cobra" ) func NewCommand(opts *cli.Options) *cobra.Command { diff --git a/internal/findatender/api.go b/internal/findatender/api.go index 9901f09..7659cd6 100644 --- a/internal/findatender/api.go +++ b/internal/findatender/api.go @@ -13,9 +13,10 @@ import ( "strings" "time" + resty "resty.dev/v3" + "git.avsdev.uk/Go/job-search/internal/findatender/ocds" "git.avsdev.uk/Go/job-search/internal/logging" - resty "resty.dev/v3" ) // Errors returned when fetching from the API. diff --git a/internal/findatender/api_test.go b/internal/findatender/api_test.go index a1fe39b..c989b90 100644 --- a/internal/findatender/api_test.go +++ b/internal/findatender/api_test.go @@ -15,9 +15,10 @@ import ( "testing" "time" + resty "resty.dev/v3" + "git.avsdev.uk/Go/job-search/internal/config" "git.avsdev.uk/Go/job-search/internal/findatender/ocds" - resty "resty.dev/v3" ) func testConfig(level string) *config.JobSearchConfig { diff --git a/internal/findatender/findatender.go b/internal/findatender/findatender.go index 7d618b1..d3a1538 100644 --- a/internal/findatender/findatender.go +++ b/internal/findatender/findatender.go @@ -5,9 +5,10 @@ import ( "log/slog" "time" + resty "resty.dev/v3" + "git.avsdev.uk/Go/job-search/internal/config" "git.avsdev.uk/Go/job-search/internal/types" - resty "resty.dev/v3" ) // FindATender is a client for the Find a Tender OCDS API (or the mock diff --git a/internal/store/migrate_test.go b/internal/store/migrate_test.go index 4661b8a..f833ab6 100644 --- a/internal/store/migrate_test.go +++ b/internal/store/migrate_test.go @@ -8,8 +8,9 @@ import ( "strings" "testing" - "git.avsdev.uk/Go/job-search/internal/store" "github.com/pressly/goose/v3" + + "git.avsdev.uk/Go/job-search/internal/store" ) // Run with: go test -tags sqlite_fts5 ./... diff --git a/internal/store/store.go b/internal/store/store.go index 8328bb0..a03fff3 100644 --- a/internal/store/store.go +++ b/internal/store/store.go @@ -12,9 +12,10 @@ import ( "time" "unicode" - "git.avsdev.uk/Go/job-search/internal/types" "github.com/jmoiron/sqlx" "github.com/mattn/go-sqlite3" + + "git.avsdev.uk/Go/job-search/internal/types" ) // ErrNotFound is returned when a requested opportunity does not exist. diff --git a/internal/websocket/client_test.go b/internal/websocket/client_test.go index 75a8641..38dc770 100644 --- a/internal/websocket/client_test.go +++ b/internal/websocket/client_test.go @@ -12,8 +12,9 @@ import ( "testing" "time" - "git.avsdev.uk/Go/job-search/internal/config" ws "github.com/coder/websocket" + + "git.avsdev.uk/Go/job-search/internal/config" ) // fakeConn is a msgConn that records how it was closed. Read blocks until its diff --git a/internal/websocket/http.go b/internal/websocket/http.go index b28aab1..85240bf 100644 --- a/internal/websocket/http.go +++ b/internal/websocket/http.go @@ -4,8 +4,9 @@ import ( "context" "net/http" - "git.avsdev.uk/Go/job-search/internal/middleware" ws "github.com/coder/websocket" + + "git.avsdev.uk/Go/job-search/internal/middleware" ) // ServeHTTP upgrades an http connection and runs the client until it closes. diff --git a/internal/websocket/http_test.go b/internal/websocket/http_test.go index 9b2f88e..70a3d59 100644 --- a/internal/websocket/http_test.go +++ b/internal/websocket/http_test.go @@ -8,9 +8,10 @@ import ( "testing" "time" - "git.avsdev.uk/Go/job-search/internal/config" ws "github.com/coder/websocket" "github.com/coder/websocket/wsjson" + + "git.avsdev.uk/Go/job-search/internal/config" ) // wsHub serves h's WebSocket clients on a test HTTP server and returns its diff --git a/internal/websocket/hub.go b/internal/websocket/hub.go index ca470df..69ddb66 100644 --- a/internal/websocket/hub.go +++ b/internal/websocket/hub.go @@ -6,8 +6,9 @@ import ( "log/slog" "sync" - "git.avsdev.uk/Go/job-search/internal/config" ws "github.com/coder/websocket" + + "git.avsdev.uk/Go/job-search/internal/config" ) // Hub tracks connected clients, WebSocket (ServeHTTP) and plain TCP diff --git a/internal/websocket/tcp_test.go b/internal/websocket/tcp_test.go index 83bee05..2fa6ef9 100644 --- a/internal/websocket/tcp_test.go +++ b/internal/websocket/tcp_test.go @@ -13,8 +13,9 @@ import ( "testing" "time" - "git.avsdev.uk/Go/job-search/internal/config" ws "github.com/coder/websocket" + + "git.avsdev.uk/Go/job-search/internal/config" ) var discardLog = slog.New(slog.NewTextHandler(io.Discard, nil))