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
Related
Using the buffalo framework,
after bootstraping it via buffalo new <project_name>
I am trying to run buffalo dev
Expecting to see:
project running on port 3000
But I am getting those error messages instead
actions/app.go:4:2: missing go.sum entry for module providing package github.com/gobuffalo/buffalo (imported by sc_api/actions); to add:go get sc_api/actions
actions/app.go:13:2: missing go.sum entry for module providing package github.com/gobuffalo/mw-csrf (imported by sc_api/actions); to add: go get sc_api/actions
actions/app.go has been generated by buffalo, but in case you are wondering the error does match the import statement in this file.
// app.go
package actions
import (
"github.com/gobuffalo/buffalo" // 1rst line
"github.com/gobuffalo/envy"
forcessl "github.com/gobuffalo/mw-forcessl"
paramlogger "github.com/gobuffalo/mw-paramlogger"
"github.com/unrolled/secure"
"sc_api/models"
"github.com/gobuffalo/buffalo-pop/v2/pop/popmw"
csrf "github.com/gobuffalo/mw-csrf" // 2nd line
i18n "github.com/gobuffalo/mw-i18n"
"github.com/gobuffalo/packr/v2"
)
What does it mean ? How do I fix it ?
It seems the issue has nothing to do with Buffalo and more with my lack of understanding of Go in general.
running go mod tidy solved the issue
This command goes through the go.mod file to resolve dependencies:
delete the packages that are not needed
download those needed
update the go.sum
I am still unsure which of those actions did the trick... but the project runs now.
ps: I'll let the in-depth explanation/correction to the Go wizard out here.
i got the same issue when building a docker image. i tried go mod tidy and
also go get -t . as suggested here https://github.com/golang/go/issues/44129. both didnt worked for me though but updating my docker builder to version 1.18 worked.
I use go mod tidy -e solved the problem. The -e flag (added in Go 1.16) causes go mod tidy to attempt to proceed despite errors encountered while loading packages.The more about mod tidy: https://go.dev/ref/mod#go-mod-tidy
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
When I run the following code with the command "go.exe run main.go", the program doesnt print text to the screen or exit.
package main
import "fmt"
func main(){
fmt.Println("Hello world")
}
go.exe version = go version go.1.5.1 windows/amd64
set GOARCH=386
set GOBIN=
set GOEXE=.exe
set GOHOSTARCH=386
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\project
set GORACE=
set GOROOT=C:\Go
set GOTOOLDIR=C:\Go\pkg\tool\windows_386
set GO15VENDOREXPERIMENT=
set CC=gcc
set GOGCCFLAGS=-m32 -mthreads -fmessage-length=0
set CXX=g++
set CGO_ENABLED=1
Any ideas what's wrong?
Thanks
EDIT:
I tried uninstalling the windows/amd64 version and installing windows/386 to no avail. It's installed in c:\Go and the PATH is set. I'm using windows 10.
Line feeds
package mainLF
LF
import "fmt"LF
LF
func main(){LF
fmt.Println("Hello world")LF
}LF
The following doesn't print to the command prompt either.
package main
//import "fmt"
func main(){
println("Hello world")
}
The following gives the error "fmt imported but not used" so it must be doing something.
package main
import "fmt"
func main(){
}
GOROOT is set to C:\Go\
PATH: C:\Go\bin
Image showing how I'm running the program
EDIT: New Image
Updated image
I ran into this same problem on a Windows 10 system. Running go run main.go would not print anything, while go build main.go followed by .\main.exe would work correctly and print out "hello, world".
The problem was due to the Comodo antivirus software quarantining the go.exe process as part of its Auto Containment feature. I believe the go run command compiles and tries to load the executable binary code of main.go into the same process, which triggers the Auto Containment to isolate the output of the application.
The initial fix was to disable Auto Containment via the Comodo Antivirus settings. Upon disabling this feature, go run main.go began to work properly.
The permanent fix was to add an "ignore" rule for the go.exe executable. This allows the Auto Containment feature to be enabled but go run to work properly.
Create a folder named ~/sample (Where ~ means your home directory)
From the terminal you can do this by entering the following commands:
mkdir sample
Below program for hello world display
package main
import "fmt"
func main() {
fmt.Println("Hello World")
}
save it as main.go in the folder we just created.
Open up a new terminal and type in the following:
cd sample
go run main.go
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.
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...