forked from quic-go/quic-go
Don't rely on GOPATH to load the certificates or error codes
GOPATH is a list of paths, similar to PATH. If someone does have a list set, the tests will try to use the full list as a path prefix to load the certificates, which won't work. But even handling GOPATH as a list does not solve the issue of what certificate or error_codes.go file to load, since the code might not be under the first one it finds. Instead, use the runtime functionality to get the filename of the path of the project at compilation time and perform the lookups relative to that, which guarantees that we're loading the files from the path of the code that is running.
This commit is contained in:
@@ -10,7 +10,8 @@ import (
|
||||
"log"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
@@ -99,6 +100,15 @@ func init() {
|
||||
})
|
||||
}
|
||||
|
||||
func getBuildDir() string {
|
||||
_, filename, _, ok := runtime.Caller(0)
|
||||
if !ok {
|
||||
panic("Failed to get current frame")
|
||||
}
|
||||
|
||||
return path.Dir(filename)
|
||||
}
|
||||
|
||||
func main() {
|
||||
// defer profile.Start().Stop()
|
||||
go func() {
|
||||
@@ -109,7 +119,7 @@ func main() {
|
||||
verbose := flag.Bool("v", false, "verbose")
|
||||
bs := binds{}
|
||||
flag.Var(&bs, "bind", "bind to")
|
||||
certPath := flag.String("certpath", os.Getenv("GOPATH")+"/src/github.com/lucas-clemente/quic-go/example/", "certificate directory")
|
||||
certPath := flag.String("certpath", getBuildDir(), "certificate directory")
|
||||
www := flag.String("www", "/var/www", "www data")
|
||||
tcp := flag.Bool("tcp", false, "also listen on TCP")
|
||||
flag.Parse()
|
||||
|
||||
Reference in New Issue
Block a user