


go grpc: cannot import github.com/golang/protobuf/proto (no required module provides package 'github.com/golang/protobuf/proto')
php editor Zimo encountered an error when using go grpc, prompting that the "github.com/golang/protobuf/proto" module could not be imported. This error is usually caused by missing required modules. Before using go grpc, we need to ensure that the protobuf library has been correctly installed and the relevant proto packages have been correctly imported in the code. Next, I will introduce in detail how to solve this problem.
Question content
When "protoc --proto_path=proto proto/*.proto --go_out=plugins", the proto file is importing "github.com/golang/protobuf/proto" Instead of "google.golang.org/protobuf/proto" =grpc:pb"command
Importing files
import ( fmt "fmt" proto "github.com/golang/protobuf/proto" math "math" ) ... > This is a compile-time assertion to ensure that this generated file // is compatible with the proto package it is being compiled against. // A compilation error at this line likely means your copy of the // proto package needs to be updated. const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
My prototype file
syntax="proto3"; message Processor{ string name=1; uint32 cores=2; uint32 min_ghz=3; uint32 max_ghz=4; }
~go/bin/protoc-gen-go-grpc has version
go: downloading google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.3.0 go: downloading google.golang.org/grpc v1.58.2 go: downloading google.golang.org/protobuf v1.28.1
what did I do
Initial installation
$ go install google.golang.org/protobuf/cmd/[email protected]
$ go install google.golang.org/grpc/cmd/[email protected]
Enter go clean -modcache before installing new packages and reinstall the latest version using the comment @latest
go version: go version on Ubuntu 20.4 go1.21.1 linux/amd64
Protocol--Version libprotoc 3.6.1
Using apt to install protobuf-compiler and golang-goprotobuf
sudo apt install protobuf-compiler sudo apt install golang-goprotobuf -dev export PATH="$PATH:$(go env GOPATH)/bin"
I think the problem is here but I don't know what to fix or how to read this
go mod graph | grep github.com/golang/protobuf example-first github.com/golang/[email protected] github.com/golang/[email protected] github.com/google/[email protected] github.com/golang/[email protected] google.golang.org/[email protected] google.golang.org/[email protected] github.com/golang/[email protected] google.golang.org/[email protected] github.com/golang/[email protected] github.com/golang/[email protected] github.com/google/[email protected] github.com/golang/[email protected] google.golang.org/[email protected] go mod why github.com/golang/protobuf go: downloading github.com/golang/protobuf v1.5.3 go: downloading github.com/google/go-cmp v0.5.5 go: downloading golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 # github.com/golang/protobuf (main module does not need package github.com/golang/protobuf)
Edit: I think I originally installed it using go get -u github.com/golang/protobuf/proto but I removed it using rm -rf $(go env GOPATH)/pkg/mod/github.com/golang binaries/protobuf/proto and install the new version using go install google.golang.org/protobuf/cmd/protoc-gen-go@latest and go install google.golang.org/grpc/cmd/protoc-gen-go- grpc@latest. It still generates go files using the old imports
Edit2: protoc-gen-go --version not found, but protoc-gen-go-grpc --version is 1.2.0. protoc --The version is libprotoc 3.6.1 whereis protocol-gen-go protoc-gen-go:/usr/bin/protoc-gen-go /home/hp/go/bin/protoc-gen-go /usr/share/man/man1/protoc-gen-go.1.gz p>
Solution
Ashttps://www.php.cn/link/a5481cd6d7517aa3fc6476dc7d9019ab<中提到的/a> Author: @puellanivis
The$PATH variable in a
Linux environment should start with /home/{username}/go/bin
and then /usr/bin
in sequence beginning. This is because we need to find google.golang.org/gprc/cmd/protoc-gen-go-grpc@latest
before /usr/bin/protoc-gen-go
.
Edit the ~/.bashrc
or ~/.bash_profile
file ($vim ~/.bashrc
) and manually export the entire path environment. In my case I had to add
export PATH=/home/hp/go/bin:/usr/local/go:/home/hp/go:usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
The above is the detailed content of go grpc: cannot import github.com/golang/protobuf/proto (no required module provides package 'github.com/golang/protobuf/proto'). For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



OpenSSL, as an open source library widely used in secure communications, provides encryption algorithms, keys and certificate management functions. However, there are some known security vulnerabilities in its historical version, some of which are extremely harmful. This article will focus on common vulnerabilities and response measures for OpenSSL in Debian systems. DebianOpenSSL known vulnerabilities: OpenSSL has experienced several serious vulnerabilities, such as: Heart Bleeding Vulnerability (CVE-2014-0160): This vulnerability affects OpenSSL 1.0.1 to 1.0.1f and 1.0.2 to 1.0.2 beta versions. An attacker can use this vulnerability to unauthorized read sensitive information on the server, including encryption keys, etc.

The article explains how to use the pprof tool for analyzing Go performance, including enabling profiling, collecting data, and identifying common bottlenecks like CPU and memory issues.Character count: 159

The article discusses writing unit tests in Go, covering best practices, mocking techniques, and tools for efficient test management.

The library used for floating-point number operation in Go language introduces how to ensure the accuracy is...

Queue threading problem in Go crawler Colly explores the problem of using the Colly crawler library in Go language, developers often encounter problems with threads and request queues. �...

Backend learning path: The exploration journey from front-end to back-end As a back-end beginner who transforms from front-end development, you already have the foundation of nodejs,...

Under the BeegoORM framework, how to specify the database associated with the model? Many Beego projects require multiple databases to be operated simultaneously. When using Beego...

The article discusses managing Go module dependencies via go.mod, covering specification, updates, and conflict resolution. It emphasizes best practices like semantic versioning and regular updates.
