S
S
s602021-07-14 18:08:09
go
s60, 2021-07-14 18:08:09

VSC only runs Go code from $GOPATH - why? How to run any open script by Ctrl+F5?

Given:
Visual Studio Code as an IDE for working with Golang.
Created GOPATH = D:\_PROJECTS\Golang projects in environment variables
Created test.go in D:\_PROJECTS\Golang projects folder.
Opened it in VSC, edited this "Hello world". Launched from the Windows console.

Then I read that you need to create three folders: src, bin, pkg
There are three folders in the D:\_PROJECTS\Golang projects\ folder: src, bin, pkg.
I copied my test.go to the folder I created test.go in the D:\_PROJECTS\Golang projects\src folder and already opened it in VCS and edited it.
But Ctrl+F5 still starts the old file Created test.go in the D:\_PROJECTS\Golang projects\test.go folder because, as I understand it, VSC looks at the GOPATH variable. Not the currently open go script.

It turns out for each program/project on go I need to fence my GOPATH like D:\_PROJECTS\Golang projects\project1\
D:\_PROJECTS\Golang projects\project2\
D:\_PROJECTS\Golang projects\project3\ and so on ? Is this idiotic?

Question:
How can I run the currently open go script using F5/Ctrl+F5 in VSC?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Pavlyuk, 2021-07-14
@pav5000

1. GOPATH is always the same and it used to be customary to create all projects in different subfolders inside it.
2. Now another system (go modules) has been adopted for a long time Read from here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question