undefined error when build go file - go

I have a simple go file like below
package main
import (
"flag"
)
var port = flag.Int("port", 23456, "port to listen.")
func main() {
flag.Parse()
}
It was no problem when I built it yesterday, but after upgrade to go1.2.1, I get below error.
d:\dev\golang>go build main.go
# flag
C:\Go\src\pkg\flag\flag.go:87: undefined: strconv.ParseBool
Tried to uninstall 1.2.1 and re-install 1.2, same result.
Can anybody tell me why? I really appreciate any help you can provide.
go version: go1.2.windows-amd64, go1.2.1.windows-amd64
windows 7 64 bit

Okay, finally I found the solution.
After I renamed C:\Go\pkg\windows_amd64 to windows_amd64\windows_amd64_111, system automatically recreated a C:\Go\pkg\windows_amd64 folder for me, and then, everything goes OK.
Still don't know why...

Related

JetBrains $GOPATH/go.mod exists but should not

Very simple code is not working. Can't find what's problem.
In console no one request didn't work. Because I dont know how use go-terminal in console. Maybe I can change some settings?
go.mod contains module "awesomeProject"
package main
import "fmt"
func main() {
fmt.Println("some text")
}
GOROOT=C:\Users\olli\sdk\go1.16.3 #gosetup
GOPATH=D:\Projects\GoLang #gosetup
C:\Users\olli\sdk\go1.16.3\bin\go.exe build -o C:\Users\olli\AppData\Local\Temp___go_build_awesomeProject.exe awesomeProject #gosetup
$GOPATH/go.mod exists but should not
Compilation finished with exit code 1
UPD:
I didn't fix the problem, just erased it and installed everything in the base folders, without changing it, and everything worked.
try to initialize the module with;
go mod init awesomeProject

Using pubsub with golang: ocgrpc.NewClientStatsHandler

I am following this tutorial to publish a topic to Pub/Sub from a golang project and here's the code I have for that project at the moment:
package main
import "cloud.google.com/go/pubsub"
import "fmt"
func main() {
fmt.Printf("hello, world\n")
}
All it does is simply imports the pubsub but when I run go get I get this error: undefined: ocgrpc.NewClientStatsHandler
C:\Users\iha001\Dev\golang-projects\src\github.com\naguibihab\golang-playarea\src\gcloud>go get
# cloud.google.com/go/pubsub
..\..\..\..\..\cloud.google.com\go\pubsub\go18.go:34:51: undefined: ocgrpc.NewClientStatsHandler
Is there anything else I need to install to get this running?
I was having the same issue on mac, using "cloud.google.com/go/pubsub" version 0.19.0. The fix for me was bumping the version down to 0.18.0.
It seems to have been an issue on the repo:
#naguibihab This is NOT a windows issue. This commit fixes the problem
be072a5. Short explanation: breaking changes where pushed on a minor
release of a google pubsub dependency:
census-instrumentation/opencensus-go#ac82455, method
NewClientStatsHandler was deleted. (They don't claim anywhere they
comply with semver).
Here's the fix mentioned in that comment: https://github.com/GoogleCloudPlatform/google-cloud-go/commit/be072a5d1d73144ae0ce1071e9bd43d1ad221581

"go get golang.org/x/tools/go/gcimporter15" fails on undefined identifiers

I'm trying to make a program dependent upon gcimporter15 for Go, and so I'm using the command "go get golang.org/x/tools/go/gcimporter15", but it fails with the error:
# golang.org/x/tools/go/gcimporter15
../../go/src/golang.org/x/tools/go/gcimporter15/bexport.go:557: undefined: constant.ToFloat
../../go/src/golang.org/x/tools/go/gcimporter15/gcimporter.go:396: pkg.SetName undefined (type *types.Package has no field or method SetName)
That appears to me that there is an error within gcimporter itself, but that doesn't make sense that I would get this when it doesn't appear that others are. Why isn't it working?
I'm using Go 1.5.3.
The godoc.org/golang.org/x/tools/go/gcimporter15 tells that the package gcimporter is deprecated and this package will be deleted in October 2017. And this new code should be used: golang.org/x/tools/go/gcexportdata instead of gcimporter .
So, what you have to do is:
$ go get godoc.org/golang.org/x/tools/go/gcexportdata
PS: Tested within Ubuntu 16.04 64bit and go version go1.6.2 linux/amd64 without any issues.
Test:
package main
import (
"fmt"
gcexportdata "golang.org/x/tools/go/gcexportdata"
)
func main() {
filename, path := gcexportdata.Find("fmt", "")
fmt.Println(filename, path)
}
Output:
/usr/lib/go-1.6/pkg/linux_amd64/fmt.a fmt
Its bad but seems there is a mismatch between the gcimporter15 and go-1.5. I faced the same problem and looked at go-1.5 code in file src/go/constant/value.go and there is no ToFloat() function in the constant package.
As #nexus66 says, the gcimporter is deprecated. So, I don't expect them to fix this. If you are using this package directly, its better to move on to the recommended gcexportdata package. If you are using a third party library which is in turn using gcimporter, may be you should upgrade to go-1.7. That's what I did and things worked fine.

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. 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
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

goconvey Please run goconvey from within your $GOPATH cannot import absolute path

I'm setting up go and trying to get a simple project working with http://goconvey.co/
I have my $GOPATH set to /Users/joe/Desktop/playground/go
and when I run
$ go get github.com/smartystreets/goconvey
it downloads all good to my GOPATH
so when I create a project here
/Users/joe/Desktop/playground/go/some-project
and run goconvey I get
2015/02/04 14:41:05 shell.go:93: Please run goconvey from within your $GOPATH
My testing code is
package main
import (
. "github.com/smartystreets/goconvey/convey"
"testing"
)
func TestStuff(t *testing.T) {
Convey("Truth", t, func() {
Convey("is falsey", func() {
So(false, ShouldBeFalse)
})
})
}
I don't know why it connot find the files.
When I run go test it works perfectly.
Help?
All go code needs to be within $GOPATH/src/ for the GoConvey UI to work.
So, if your $GOPATH is set to
/Users/joe/Desktop/playground/go
then you will need to put your project at
/Users/joe/Desktop/playground/go/src/some-project
Your code is currently at
/Users/joe/Desktop/playground/go/some-project
Having said all that, the error message should probably be modified to read something like this:
Please run goconvey from within $GOPATH/src (also, symlinks might be problematic).
The name of the variable referenced by #VonC is probably a slight misnomer in this case.

Resources