Skip to content

Commit 470a32d

Browse files
authored
docs(install-guide): update Go 1.24 tool directive usage (#5298)
The previous installation guide relied on tools.go for tracking dependencies. This update replaces it with the new tool directive introduced in Go 1.24. Fixes #5254
1 parent d9141b9 commit 470a32d

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

README.md

+42
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,48 @@ This will place four binaries in your `$GOBIN`;
9797

9898
Make sure that your `$GOBIN` is in your `$PATH`.
9999

100+
### **Using the `tool` Directive in Go 1.24**
101+
102+
Starting from Go 1.24, the `tool` directive in `go.mod` provides a structured way to track and manage executable dependencies. This replaces the previous workaround of using a separate `tools.go` file with blank imports.
103+
104+
#### **Tracking Tools in `go.mod`**
105+
106+
Instead of manually importing tool dependencies in a Go source file, you can now use the `tool` directive in `go.mod` to declare the tools your project depends on. For example:
107+
108+
```go
109+
module tools
110+
111+
go 1.24
112+
113+
tool (
114+
github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway
115+
github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2
116+
google.golang.org/grpc/cmd/protoc-gen-go-grpc
117+
google.golang.org/protobuf/cmd/protoc-gen-go
118+
)
119+
```
120+
121+
#### **Managing Tool Dependencies**
122+
123+
To add tools to your module, use the `-tool` flag with `go get`:
124+
125+
```sh
126+
go get -tool github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway
127+
go get -tool github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2
128+
go get -tool google.golang.org/protobuf/cmd/protoc-gen-go
129+
go get -tool google.golang.org/grpc/cmd/protoc-gen-go-grpc
130+
```
131+
132+
This automatically updates `go.mod`, adding the tools under the `tool` directive along with `require` statements to ensure version tracking.
133+
134+
### Install Tools
135+
136+
Once the tool dependencies are properly recorded in the `go.mod` file, simply execute the following command in the root directory of your project:
137+
138+
```sh
139+
go install ./...
140+
```
141+
100142
### Download the binaries
101143

102144
You may alternatively download the binaries from the [GitHub releases page](https://github.com/grpc-ecosystem/grpc-gateway/releases/latest).

0 commit comments

Comments
 (0)