Home >Backend Development >Golang >Solve the problem of xxx is deprecated when go get

Solve the problem of xxx is deprecated when go get

藏色散人
藏色散人forward
2021-12-27 15:42:393811browse

This article is introduced by the golang tutorial column to introduce to you the problem of ‘xxx is deprecated’ when go get occurs. I hope it will be helpful to friends in need!

Recently, I need to use protobuf for grpc when learning go. The protoc-gen-go package can generate golang's protobuf version protocol code

In the mac development environment, an error will be reported when using the following command to install the package

go get -u github.com/golang/protobuf/protoc-gen-go

The error content is the following:

Solve the problem of xxx is deprecated when go get

The error message is that after version go1.17, the use of go get to install packages is not supported, but through go Install the package by install

Here I used my personal solution

Enter golang/protobuf to download the source code

  • Enter the protobuf directory
  • Enter the protoc-gen-go directory
  • Run the command go build
  • Run the command go install

Here is a brief introduction to go build and go install

go build

By go build plus the name of the Go source file to be compiled, we can get an executable file. By default, the name of this file is the name of the source file. Remove the .go suffix.

go install

Compared with the build command, the install command will also install the executable file or library file to the agreed directory after compiling the source code.

  • go installThe compiled executable file is named after the directory name (DIR) where it is located

  • go install installs the executable file to In the bin directory at the same level as src, the bin directory is automatically created by go install.

  • go install compiles the various packages that the executable file depends on and places them in the pkg directory at the same level as src. Next

At this time, the executable file of protoc-gen-go will exist in the /bin directory of GOPATH

Solve the problem of xxx is deprecated when go get

Change $ The GOPATH/bin directory is added to the environment variable, so that subsequent commands generated by go install can be executed directly.

Now edit the /etc/profile file and add this text to the profile file. The $GOPATH variable here is the GOPATH path of your local GO

export PATH="$PATH: $GOPATH/bin" >> /etc/profile

The problem is solved! You can export golang's protocbuf protocol code through the command protoc --go_out=plugins=grpc:. *.proto

Solve the problem of xxx is deprecated when go get

The above is the detailed content of Solve the problem of xxx is deprecated when go get. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:learnku.com. If there is any infringement, please contact admin@php.cn delete