douweida2669 2016-08-24 00:20
浏览 2483
已采纳

如何在Golang中设置GODEBUG环境变量,以便可以在net / http中使用godebug

I want to step through my program using Godebug. However because I'm using net/http I get errors such as:

/home/heath/go/src/net/http/h2_bundle.go:45:2: could not import golang_org/x/net/http2/hpack (cannot find package "golang_org/x/net/http2/hpack" in any of:
    /home/heath/go/src/golang_org/x/net/http2/hpack (from $GOROOT)

/x/net/http2/hpack does exist in my GOPATH but in ~heath/go/src/golang.org ... not golang_org (not sure what's happening there)

I have read that this error occurs because godebug doesn't support http2 yet (can't find source).

I have tried to disable http2server and http2client by setting the GODEBUG env both in init() and on the command line. I have also confirmed that these settings are being set by doing a fmt.Println("GODEBUG", os.Getenv("GODEBUG"). As per instructions located here

GODEBUG=http2client=0  # disable HTTP/2 client support
GODEBUG=http2server=0  # disable HTTP/2 server support

My simple code example to replicate the error is:

  package main

  import "fmt"
  import "net/http"
  import "os"

  func init() {

      os.Setenv("GODEBUG", "http2server=0,http2client=0")

  }

  func main() {

      fmt.Println("GODEBUG", os.Getenv("GODEBUG"))

      _ = "breakpoint"
      fmt.Println("Hello, World!")
      http.ListenAndServe(":8080", nil)
  }

godebug run example.go

I am running Go version:

go version go1.7 linux/amd64

  • 写回答

1条回答 默认 最新

  • douya7282 2016-08-25 00:15
    关注

    This is probably not the correct way to do things. But I copied the http2 package from my vendor directory under $GOROOT/src/vendor to the src directory under my $GOPATH/src.

    If anyone has any further input on the correct way to reference vendor directories please add your thoughts. Just putting my workaround here in case someone else comes across the same issue.

    Edit: Actually a 'nicer' way to do things was to do an ln -s ..src/vender/github_org to ../src/github_org

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器