2

It appears that I cannot import this package: github.com/golang/protobuf/proto

When I try to build or use go get I 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

It is a popular package, I am surprised it does not seem to be working. https://godoc.org/github.com/golang/protobuf/proto#Marshal

Has anybody encountered this?

Update:

I am simply trying to import this:

import (
    "bytes"
    "context"
    "encoding/json"
    "errors"
    "fmt"
    "github.com/golang/protobuf/proto"
)

GoLang does not resolve proto in the above path...

I try to install like this:

$ 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

Update2, not sure how the file helps but here it is:

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
7
  • 1
    go get github.com/golang/protobuf/proto works just fine. Please show the code you want to run. Also what version of Go are you using?
    – icza
    Oct 2, 2019 at 11:59
  • go version go1.13.1 darwin/amd64 Oct 2, 2019 at 12:01
  • It works for me. It might be a Go module config error for you. Try running go mod tidy, then go build.
    – icza
    Oct 2, 2019 at 12:08
  • strange, I get this for tidy:go: failed to lock file at /Users/CoolUser/go/pkg/mod/cache/lock Oct 2, 2019 at 12:10
  • I cannot seem to import my local packages as well, maybe the problems are related Oct 2, 2019 at 12:13

2 Answers 2

4

It turns out there was something wrong with the module cache, that's why the go tool was not able to fetch / update dependencies.

In such cases, clearing the module cache (might) help:

go clean -modcache
2
  • Any idea how the cache got into a bad state? Is there a test to verify the current integrity of the cache without clearing it?
    – colm.anseo
    Oct 3, 2019 at 2:53
  • Not sure, maybe it has something to do with me rearranging the directories of my packages a bit. Oct 3, 2019 at 2:58
1

On the Terminal window, please run the following commands,

go clean -modcache

go get -u github.com/golang/protobuf/proto

Then run the following commands to get the packages downloaded and update in the .mod file

go mod init Version1
go mod tidy

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.