# Fix "go get: installing executables with 'go get' in module mode is deprecated" in a mockgen Makefile

Yes. An agent rewrites a Makefile target that installed mockgen with go get, runs it under a current Go to show what breaks, and regenerates the mocks with go run.

[Run this on Rush](https://cloud.getrush.ai/run/fix-go-get-installing-executables-deprecated/gomock/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads the Makefile and the module file before running anything, because the deprecated pattern lives in build scripts, not in Go source. In a CLI like uber/assume-role-cli, `go.mod` says `go 1.13` and requires `github.com/golang/mock v1.3.1`, `.travis.yml` tests on Go 1.13.x, and the `mocks` target in the `Makefile` runs `go get -u github.com/golang/mock/gomock`, then `go get -u github.com/golang/mock/mockgen`, then pipes `mockgen -package=mocks github.com/uber/assume-role-cli AWSProvider,AWSConfigProvider` through `sed` into `mocks/aws_mocks.go` and prepends the licence header. The `README` also tells users to install the tool itself with `go get -u github.com/uber/assume-role-cli/cli/assume-role`.

Then it runs `make mocks` under the sandbox's Go, 1.25.1, and records what each line does now. `go help get` states the change: in earlier versions `go get` built and installed packages, now it is dedicated to adjusting dependencies in `go.mod`, and `go install pkg@version` installs commands. So the first `go get -u` does not install anything; it rewrites `go.mod`, moving `golang/mock` from v1.3.1 to v1.6.0 and bumping `golang.org/x/crypto`, and adds 23 lines to `go.sum`. The second `go get -u` fails outright: `go: golang.org/x/mod@v0.43.0 requires go >= 1.26.0 (running go 1.25.1)`, repeated for `x/sys` and `x/tools`, because `-u` reaches for the newest modules and those now need a newer toolchain than `go 1.13` in the module file. `make` stops with exit 2 and `mockgen` is never on the path. Outside any module the message is the one developers search for: `'go get' is no longer supported outside a module. To build and install a command, use 'go install' with a version, like 'go install example.com/cmd@latest'`.

The fix separates the tool from the dependency. The target becomes `go run github.com/golang/mock/mockgen@v1.3.1 -package=mocks ...`, which builds the generator at the version `go.mod` already requires, leaves `go.mod` and `go.sum` untouched (`git status` is clean afterwards), and needs no `GOPATH/bin` on the path. `go install github.com/golang/mock/mockgen@v1.6.0` is the alternative when a persistent binary is wanted; the agent shows it lands in `GOPATH/bin` and names the version pin either way. The Makefile's `[ "$$INSTALL_HOOK" == "" ]` line also prints `[: unexpected operator` under `/bin/sh`, a second finding reported with its fix, `=`.

Proof is the regenerated file and the tests. `mockgen` at v1.3.1 regenerates `mocks/aws_mocks.go` with the same two mocks; the only diff against the committed file is `m.ctrl.T.Helper()` lines the committed copy lacks, which dates the committed mocks to an older generator. `go build ./...` and `go test -short ./...` pass for both packages with tests, before and after.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Our Makefile installs mockgen with \"go get -u\" and CI fails since the Go toolchain was updated. Read the Makefile, go.mod and the CI config, run the mock generation target under the current Go and quote what each go get line does now, including any change to go.mod or go.sum. Rewrite the target to build the generator at the version go.mod requires with go run, or go install with an explicit version, so the module file is not modified as a side effect, regenerate the mocks and diff them against the committed file, run go build and go test, and open a pull request with the before-and-after output and any other shell error the Makefile prints.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

A pull request that changes the `mocks` target to `go run github.com/golang/mock/mockgen@v1.3.1`, drops the two `go get -u` lines, and fixes the `==` in the hook shell test. The description quotes `go help get` on what `go get` does now, the `go.mod` rewrite the old target caused, the `requires go >= 1.26.0` failure from the second line, and a clean `git status` after the new target runs.

A reviewer checks that the generator version matches the `golang/mock` requirement in `go.mod`, that the regenerated `mocks/aws_mocks.go` differs from the committed file only by the `T.Helper()` lines a newer generator adds, and that `go test -short ./...` passes. Whether to commit the regenerated mocks is left to them.

The description names what the agent did not do: it did not move the project from `github.com/golang/mock` to `go.uber.org/mock`, and it did not change the `README` install line, both of which are separate decisions.

## Run it on every CI failure on the mocks target

The pattern surfaces when the CI image's Go moves, so the failing job is the trigger. A step in the workflow posts the job log to a Rush `webhook` trigger with `Authorization: Bearer` and the trigger's secret when it contains `'go get' is no longer supported` or a `requires go >=` line, and the run opens the Makefile pull request; the log follows the prompt as data.

For every Go module in the organisation that still generates mocks this way, your server sends this request once per repository, each with its own UUID as `request_id` so a retry returns the run already started, and reads each `run.completed` webhook; a key starts at most `max_concurrent` runs at once and queues the rest.

## Why run it on Rush?

The deprecation message people search for was printed by one Go release; later toolchains do something different and quieter, rewriting `go.mod` on the way to a failure about toolchain versions. In a Rush sandbox the agent runs the real target under a current Go, keeps the `go.mod` diff and every error line, and checks that the replacement leaves the module file untouched, so the pull request shows what the old target does today rather than what a 2021 blog post says.

A build-script fix is only done when the generated output is checked. The agent regenerates the mocks, diffs them against the committed file, and runs the tests, so the reviewer reads a Makefile change with the generator version pinned and the evidence that nothing else moved.

## Frequently asked questions

### Why does go get no longer install mockgen?

Since the module-mode change, `go get` only edits `go.mod` and `go.sum`; `go help get` says so directly and points to `go install pkg@version` for commands. The old target ran, changed the dependency versions as a side effect, and never produced a binary.

### go run or go install?

`go run github.com/golang/mock/mockgen@v1.3.1` builds and runs the generator at the version `go.mod` already requires and leaves no binary to keep on the path. `go install ...@v1.6.0` puts one in `GOPATH/bin`. Both pin an explicit version; the pull request uses `go run` so the module file is never touched.

### Why did go.mod change when I ran the old target?

Because `go get -u` upgrades the named module and its dependencies: `golang/mock` moved from v1.3.1 to v1.6.0 and `golang.org/x/crypto` moved with it, with 23 new `go.sum` lines. The second line then failed because the newest `x/mod` needs Go 1.26 or newer.

### Should I switch to go.uber.org/mock while I am here?

That is a separate change: it alters import paths in the generated file and in tests. The pull request keeps `github.com/golang/mock` at the version `go.mod` requires and names the migration as follow-up work.

## More GoMock jobs

- [Migrate From golang/mock to go.uber.org/mock](https://getrush.ai/run/migrate-golang-mock-to-uber-mock/gomock/)

## More jobs like this: Fix a bug from an alert

- [Fix a Django App From a Grafana Alert](https://getrush.ai/run/fix-grafana-alerts/django/)
- [Fix a FastAPI App From a Grafana Alert](https://getrush.ai/run/fix-grafana-alerts/fastapi/)
- [Fix a Go Service From a Grafana Alert](https://getrush.ai/run/fix-grafana-alerts/go/)
- [Fix the Cause of a Grafana Alert in Kubernetes](https://getrush.ai/run/fix-grafana-alerts/kubernetes/)
- [Fix a NestJS API From a Grafana Alert](https://getrush.ai/run/fix-grafana-alerts/nestjs/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
