教程集 www.jiaochengji.com
教程集 >  Golang编程  >  golang教程  >  正文 golang.org/x/net/trace重复错误

golang.org/x/net/trace重复错误

发布时间:2021-05-06   编辑:jiaochengji.com
教程集为您提供golang.org/x/net/trace重复错误等资源,欢迎您收藏本站,我们将为您提供最新的golang.org/x/net/trace重复错误资源

使用grpc进行开发时,启动grpc client报错如下:

panic: /debug/requests is already registered. You may have two independent copies of golang.org/x/net/trace in your binary, trying to maintain separate state. This may involve a vendored copy of golang.org/x/net/trace.

错误原因

golang.org/x/net/trace 在整个$GOPATH中有重复的副本,包括其他项目的vendor目录中依赖了golang.org/x/net包。

错误提示

goroutine 1 [running]:
golang.org/x/net/trace.init.0()
	/Users/lcl/go/src/golang.org/x/net/trace/trace.go:123  0x17e

查看golang.org/x/net/trace/trace.go文件中的init()方法

// HTTP ServeMux paths.
const (
	debugRequestsPath = "/debug/requests"
	debugEventsPath   = "/debug/events"
)

...

func init() {
	_, pat := http.DefaultServeMux.Handler(&http.Request{URL: &url.URL{Path: debugRequestsPath}})
	if pat == debugRequestsPath {
		panic("/debug/requests is already registered. You may have two independent copies of "  
			"golang.org/x/net/trace in your binary, trying to maintain separate state. This may "  
			"involve a vendored copy of golang.org/x/net/trace.")
	}

	// TODO(jbd): Serve Traces from /debug/traces in the future?
	// There is no requirement for a request to be present to have traces.
	http.HandleFunc(debugRequestsPath, Traces)
	http.HandleFunc(debugEventsPath, Events)
}

解决办法

  1. 使用包管理工具govendor,用于将go build时的应用路径搜索调整成为当前项目目录/vendor目录方式 推荐
  2. $GOPATH目录下只保留一份golang.org/x/net/trace,删除所有项目vendor目录中的golang.org/x/net/trace 不推荐
  3. 独立工程目录,每个项目设置GOPATH 不推荐
到此这篇关于“golang.org/x/net/trace重复错误”的文章就介绍到这了,更多文章或继续浏览下面的相关文章,希望大家以后多多支持JQ教程网!

您可能感兴趣的文章:
golang.org/x/net/trace重复错误
go mod使用
golang http client 使用gzip_一次gRPC使用不当导致goroutine泄漏排查记录
Golang微服务micro 环境搭建,纯小白..
Windows10 golang gRPC环境搭建
Golang 无法下载依赖解决方案 unrecognized import path "golang.org/x/net
安装 paho mqtt golang包
php Exception打印error trace 实例
Go语言学习笔记 - 第五章 函数(The Go Programming Language)
shell 获取 alert_sid.log 错误日志的方法

[关闭]
~ ~