简体   繁体   English

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

[英]How do I set GODEBUG environment variables in Golang so I can use godebug with net/http

I want to step through my program using Godebug . 我想使用Godebug逐步完成程序。 However because I'm using net/http I get errors such as: 但是,由于我使用的是net / http,因此出现如下错误:

/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) / x / net / http2 / hpack确实存在于我的GOPATH中,但是存在于〜heath / go / src / golang.org中……不是golang_org(不确定那里发生了什么)

I have read that this error occurs because godebug doesn't support http2 yet (can't find source). 我已经读到发生此错误,是因为godebug还不支持http2(找不到源)。

I have tried to disable http2server and http2client by setting the GODEBUG env both in init() and on the command line. 我试图通过在init()和命令行中设置GODEBUG env来禁用http2server和http2client。 I have also confirmed that these settings are being set by doing a fmt.Println("GODEBUG", os.Getenv("GODEBUG"). As per instructions located here 我还确认通过执行fmt.Println(“ GODEBUG”,os.Getenv(“ GODEBUG”)来设置这些设置。按照此处的说明进行操作

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版本:

go version go1.7 linux/amd64 go版本go1.7 linux / amd64

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. 但是我将http2软件包从$ GOROOT / src / vendor下的供应商目录复制到$ GOPATH / src下的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 编辑:实际上,做事的“更好”方法是对../src/github_org做ln -s ..src / vender / github_org

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM