无法使用protobuf包

Fai*_*est 2 go protocol-buffers grpc

看来我无法导入这个包:github.com/golang/protobuf/proto

当我尝试build或使用时go get我得到:

cannot load github.com/golang/protobuf/proto: module github.com/golang/protobuf@latest (v1.3.2) found, but does not contain package github.com/golang/protobuf/proto
Run Code Online (Sandbox Code Playgroud)

这是一个流行的软件包,我很惊讶它似乎不起作用。 https://godoc.org/github.com/golang/protobuf/proto#Marshal

有人遇到过这种情况吗?

更新

我只是想导入这个:

import (
    "bytes"
    "context"
    "encoding/json"
    "errors"
    "fmt"
    "github.com/golang/protobuf/proto"
)
Run Code Online (Sandbox Code Playgroud)

GoLang 不解析上述路径中的 proto...

我尝试像这样安装:

$ go get github.com/golang/protobuf/proto
go: finding github.com/golang/protobuf/proto latest
go get github.com/golang/protobuf/proto: module github.com/golang/protobuf@upgrade (v1.3.2) found, but does not contain package github.com/golang/protobuf/proto
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

icz*_*cza 5

事实证明模块缓存有问题,这就是该go工具无法获取/更新依赖项的原因。

在这种情况下,清除模块缓存(可能)会有所帮助:

go clean -modcache
Run Code Online (Sandbox Code Playgroud)