How to run the whole project in GoLand? - go

I have a small project with several .go files. When I run main.go only this compiles but nothing else, so my application crushes. I understand that I have to change settings in Run -> Edit Configurations, but don't know what to do exactly. IDE also doesn’t see terminal pre-compiled package, so "Package" option instead of "File" doesn't work.

To run the whole project you have to go Run -> Edit Configuration, set Run Kind to Package and type in field Package your project directory name.

Related

VS Code showing me "Error loading workspace: found module "main.go" twice in the workspace"

I am using the primary GO extension.
I use VS code a lot, now I'm learning GO lang.
And when I open VS Code every time I'm getting this:
Error loading workspace: found module "main.go" twice in the workspace.
While running the code it's giving the right output.
I don't know how to fix this.
Anybody, help me with this error.
It would be better to open in VSCode only one folder with its own go.mod project.
A workspace with multiple go.mod/project should be supported with 1.18
The go command now supports a "Workspace" mode.
If a go.work file is found in the working directory or a parent directory, or one is specified using the -workfile flag, it will put the go command into workspace mode.
In workspace mode, the go.work file will be used to determine the set of main modules used as the roots for module resolution, instead of using the normally-found go.mod file to specify the single main module.
As described in "How to make VScode Go work in a Multi-Module Repo" from Varun Kumar, this used to work:
If you want to work with all the nested modules in a single workspace, there is an opt-in module feature that allows to work with multiple modules without creating workspace folders for each module. Set this in your settings -
"build.experimentalWorkspaceModule": true
But as per september 2022 is deprecated.
See more at gopls documentation "Setting up your workspace".

How to proper configure "Go Build" and what are the differences between Run Kind

I am new to Go language and also to the IDE GoLand so I am sorry if this is very basic.
I am currently trying to configure Run Kind for package for all my files, the problem is I cannot seem to get the configuration straight, I get this error:
"can't load package: package Course: unknown import path "Course": cannot find module providing package Course"
My GOROOT is the standard in C: and GOPATH is in my directory of workplace with the folders: scr, bin and pkg. Inside scr is course folder with training files for Go.
I have tried to google every option on how to properly configure the go Build configuration, I might be missing to install packages not sure to be honest, I have installed the gotools and everything from golang.org, and tried following the guide from GoLand in JetBrains but no luck in properly configuring package, or Dir options.
I can create a go Build for each file using Run Kind: File, but I want to create one for all the files inside the folder not one each time I want to run one.
Also I have no idea what -i in Go tool arguments means.
I believe what you need to do is simply enable go module integration. Find the setting at File | Settings | Go | Go Modules (vgo). In that panel also make sure Vgo executable is set to your Project SDK. If it's still not working, enabling the vendor experiment option at File | Settings | Go | Build Tags & Vendoring may help. Be sure your project specific settings aren't overriding these values as well.

Run a spring-boot project but pages of another project show up

The keyword is too verbose to help me find anything useful. Please pardon me if it's a stupid question.
I have two spring-boot projects, A and B, in the same directory. I run
mvn clean
mvn compile
mvn package
mvn spring-boot:run
in the directory of project A and want to run A. However, the pages of project B shows up (both of them use localhost:8080).
I tried the following but none worked:
Moved and renamed A to another directory and ran all the above commends again;
Clean brower cache or open in incog window;
Remove .m2 folder;
Reboot my laptop;
Run with IDE, mvn spring-boot:run, and java -jar target/ProjectA.jar;
Invalidate Cache/Restart in IntelliJ.
Also:
If I break Project A (make it fail to compile), mvn compile will fail;
If I break Project B, running A will still give me B;
If I change the contents of html files in B, it won't change the showing pages;
If I debug the project A, it will hit the main function in #SpringBootApplication;
Everything is running on Win10, no container or VM.
It seems I am running Project A, but it has neither MvcConfig nor html templates, where are those pages from? I did a thorough search for page contents, but the project directory of A didn't contain anything like that. So it must from somewhere else.
Github: https://github.com/PhoenixPan/finishthem-api-server
(doesn't have any visible html page)
Hope someone could explain why this is happening and how should I prevent it... Thanks.
Have you tried running your project A from your IDE as a simple java application? You can run a Spring Boot application from your IDE as a simple Java application. However, you first need to import your project. Import steps vary depending on your IDE and build system. Most IDEs can import Maven projects directly. For example, Eclipse users can select Import…​ → Existing Maven Projects from the File menu.

How to run/debug a beego app using Gogland (go language)

Im using Gogland (IDE from JetBrains. Version 1.0 Preview/EAP Feb, 10 2017) to create a Beego web app.
I can run it from command line with:
bee run
and everything works.
However if I run it from the IDE with the following configuration
when I go to localhost:8080 it says it can not find the template file in path:
I thought it was related to GOPATH, but then I realized that Gogland IDE is probably running
go run main.go
instead of
bee go
and when I checked runing
go run main.go
from the shell, I got the same issue: cant find the template.
I even tried to run the 'bee' command from the IDE. I partially succeed. With this configuration:
I can run it from the IDE, but the debugger doesn't stop in any breakpoint. IE: I can only run (but not debug) it, from Gogland.
So my question is how to make gogland IDE debug a beego project
Use Delve and Remote Debugging Configuration(start from gogland eap9).
Run your bee app like:
bee dlv -package="app_name" -port=2345
On gogland make configuration Go Remote with port which you set previous.
You cannot change the IDE to run the bee command. However, you can change the run configuration to a Go Application by going to Run | Edit Configurations | + | Go Application select the package type then type the full package name (github.com/dlsniper/demo for example if your package main is under GOPATH/src/github.com/dlsniper/demo) and make sure the working directory is where you need it to be. Hope it helps.
I resolve this by setting:
beego.BConfig.WebConfig.ViewsPath="/Users/xxxxx/go/src/xxxxxxx/views" // your views directory
by the way: if you have staticpath , you should also use absolute path.
eg: beego.SetStaticPath("/static", "/Users/xxx/go/src/xxxx/static")
it's only used when debug, if you publish your program, you should remove this hard code config.

How to setup Go in GoClipse

I installed goclipse in my eclipse, and setup the preferences as follows :
Preferences->Go->Tools
ProjectExplorer
Now when I create a new GoFile (HelloWorld.src), the file is saved in D:/GO/TestProject/src. But when I build the same file, the bin and pkg folders are empty and hence when I run the file the following error comes :
resource does not have a corresponding go package
Unable to run the code because of this error.
Your project path should be D:\GO\src\TestProject in order to match the workspace expected as described in https://golang.org/doc/code.html
Then, your GOPATH should point to D:\GO (NOT ...\src)
The go tool will automatically use $GOPATH/src, $GOPATH/bin or $GOPATH/pkg when appropiate for each case.
And as icza pointed out, your program should have a package main statement on the top of your go file to be recognized as an executable, unless you want to create a package, in that case, you should name your package as you want.

Resources