gpt4 book ai didi

go - 无法使用protobuf包

转载 作者:行者123 更新时间:2023-12-02 18:30:23 25 4
gpt4 key购买 nike

我似乎无法导入此包:github.com/golang/protobuf/proto

当我尝试构建或使用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

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

有人遇到过这种情况吗?

更新:

我只是想导入这个:

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

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

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

关于go - 无法使用protobuf包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58200259/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com