无法使用 protobuf 包
Unable to use the protobuf package
我似乎无法导入这个包:github.com/golang/protobuf/proto
当我尝试 build 或使用 go get 我 get:cannot 加载 github.com/golang/protobuf/proto: 找到模块 github.com/golang/protobuf@latest (v1.3.2),但不包含包 github.com/golang/protobuf/proto
这是一个流行的软件包,我很惊讶它似乎不起作用。
https://godoc.org/github.com/golang/protobuf/proto#Marshal
有人遇到过吗?
更新:
我只是想导入这个:
进口 (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"github.com/golang/protobuf/proto"
)
GoLang 没有解析上述路径中的 proto...
我尝试这样安装:
$ 去获取 github.com/golang/protobuf/proto
开始:找到 github.com/golang/protobuf/proto 最新的
go get github.com/golang/protobuf/proto: 找到模块 github.com/golang/protobuf@upgrade (v1.3.2),但不包含包 github.com/golang/protobuf/proto
Update2,不确定该文件有何帮助,但它是:
package main
import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"github.com/golang/protobuf/proto"
"go_poc/plugins/com_styx_proto"
"io/ioutil"
"net/http"
"time"
)
func init() {
fmt.Println("styxBotDetect plugin is loaded!")
}
func (r registrable) RegisterHandlers(f func(
name string,
handler func(
context.Context,
map[string]interface{},
http.Handler) (http.Handler, error),
)) {
f(pluginName, r.registerHandlers)
}
func (r registrable) registerHandlers(ctx context.Context, extra map[string]interface{}, handler http.Handler) (http.Handler, error) {
// skipping some lines here
styxRqBytes, err := proto.Marshal(styxRq)
if err != nil {
http.Error(w, err.Error(), http.StatusNotAcceptable)
return
}
// more code
事实证明模块缓存有问题,这就是 go
工具无法获取/更新依赖项的原因。
在这种情况下,清除模块缓存(可能)有帮助:
go clean -modcache
在终端 window 上,请 运行 以下命令,
go clean -modcache
go get -u github.com/golang/protobuf/proto
然后运行以下命令来下载包并更新.mod文件
go mod init Version1
go mod tidy
我似乎无法导入这个包:github.com/golang/protobuf/proto
当我尝试 build 或使用 go get 我 get:cannot 加载 github.com/golang/protobuf/proto: 找到模块 github.com/golang/protobuf@latest (v1.3.2),但不包含包 github.com/golang/protobuf/proto
这是一个流行的软件包,我很惊讶它似乎不起作用。 https://godoc.org/github.com/golang/protobuf/proto#Marshal
有人遇到过吗?
更新:
我只是想导入这个: 进口 ( "bytes" "context" "encoding/json" "errors" "fmt" "github.com/golang/protobuf/proto" )
GoLang 没有解析上述路径中的 proto...
我尝试这样安装: $ 去获取 github.com/golang/protobuf/proto 开始:找到 github.com/golang/protobuf/proto 最新的 go get github.com/golang/protobuf/proto: 找到模块 github.com/golang/protobuf@upgrade (v1.3.2),但不包含包 github.com/golang/protobuf/proto
Update2,不确定该文件有何帮助,但它是:
package main
import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"github.com/golang/protobuf/proto"
"go_poc/plugins/com_styx_proto"
"io/ioutil"
"net/http"
"time"
)
func init() {
fmt.Println("styxBotDetect plugin is loaded!")
}
func (r registrable) RegisterHandlers(f func(
name string,
handler func(
context.Context,
map[string]interface{},
http.Handler) (http.Handler, error),
)) {
f(pluginName, r.registerHandlers)
}
func (r registrable) registerHandlers(ctx context.Context, extra map[string]interface{}, handler http.Handler) (http.Handler, error) {
// skipping some lines here
styxRqBytes, err := proto.Marshal(styxRq)
if err != nil {
http.Error(w, err.Error(), http.StatusNotAcceptable)
return
}
// more code
事实证明模块缓存有问题,这就是 go
工具无法获取/更新依赖项的原因。
在这种情况下,清除模块缓存(可能)有帮助:
go clean -modcache
在终端 window 上,请 运行 以下命令,
go clean -modcache
go get -u github.com/golang/protobuf/proto
然后运行以下命令来下载包并更新.mod文件
go mod init Version1
go mod tidy