JavaRush /Courses /Go SELF /Creating Your First Project in GoLand

Creating Your First Project in GoLand

Go SELF
Level 5, Lesson 3
Available

1. Step-by-Step Creation of a New Project

A project in GoLand is not just a folder with files, but an entire container where the IDE stores everything related to your future program. The project contains:

  • source code, files with the .go extension;
  • project settings, for example, which version of the Go compiler to use;
  • dependency management files (go.mod);
  • auxiliary files and resources.

Launching GoLand

On the welcome screen, click the New Project button. If another project is already open, click File -> New -> Project... in the top menu.

New Project in GoLand

Configuring Project Parameters

Pay attention to the left menu of the window: the Go item must be selected there. Now let's go over the main fields:

  • Location: the path where the project will be stored on your computer. The last word in the path is the name of the project folder. You can leave the default or write another one, let it be tasker.
  • GOROOT: the path to the installed Go compiler. If the field is empty or shows an old version, click the Add SDK... button (or the plus sign), select Download... and specify version 1.25. GoLand will automatically download and install the official distribution of the required version into your system.
  • Enable vendoring support automatically: Vendoring is a mechanism for locally storing all downloaded external libraries directly inside your project, in a special vendor folder. This guarantees that the project will build even without internet access or if the original library repository is deleted. Checking this box tells the IDE to automatically use this folder to resolve imports if it exists. For starting your learning journey, we won't need external libraries yet, so you can simply leave this option in its default state.
  • Environment: in this field, you can set specific system variables that will be applied when the Go compiler and utilities run within this project (e.g., GOPROXY, GOPRIVATE, or CGO_ENABLED). Fine-tuning the environment is often required in corporate networks for downloading packages via internal servers or for cross-compilation for other operating systems. At this stage of learning, standard system settings are more than enough, so the field can be left empty.
  • Add sample code: make sure to check this box. The IDE will automatically create a basic file with a main function and sample code for us, so we don't have to write it from scratch.

All settings are done. Click Create.

GoLand will create the project structure and open the main editor window. At the bottom of the screen, you might see Indexing... — this means the IDE is reading the language's standard library to help you with code completion. Just wait a minute.

Upon the first launch on Windows, you might see a notification: "Microsoft Defender may affect IDE performance". Feel free to click Automatically or Exclude folders. The IDE will add the project folder to the temporary exclusions of your antivirus so that code building works fast.

2. Brief Overview and First Code

You now see a code editor with the automatically generated main.go file.

1. Sidebar with tools.

2. Project — the main window for navigating the project structure (on the left).

3. The currently open file main.go in the center.

4. Buttons for Run ▶ and Debug in the top panel and on the editor's margins.

Code Analysis

Thanks to the "Add sample code" checkbox, the IDE generated an example that perfectly demonstrates basic Go syntax:

  • package main — indicates that we are creating an executable program (binary file), not a library.
  • import "fmt" — importing a package from the standard library for outputting text. The IDE added it automatically.
  • //TIP ... — a hint comment with a link to documentation.
  • name := "Go" — we created a variable name. Note: we didn't have to specify the variable's type (e.g., string); Go inferred it from the value thanks to the := operator.
  • fmt.Printf(...) — formatted text output. The %s symbol acts as a placeholder where the value of the name variable is inserted.
  • for i := 1; i <= 5; i++ — this is a loop. The code inside the curly braces will execute 5 times (for numbers from 1 to 5).

A red circle on the left margins or an icon in the code is an entry point into debug mode (breakpoint). We'll talk about it in the next lecture. If you accidentally set such a point, just click it again to remove it.

3. Project Structure

Let's take a closer look at the project structure on the left (the Project window).

  • .idea — an internal hidden folder of the IDE with project settings. You don't need to modify it manually.
  • tasker — the root folder of the project. Unlike languages that require bulky structures (like an src folder), in Go, source files are often located right in the root.
    • main.go — the file we are currently looking at. Inside it is the func main() function. This is the "entry point" — this is exactly where the execution of any program begins.
    • go.mod — the module file. The IDE created it automatically. It stores the name of your module and the language version.
  • External Libraries — a virtual folder displaying connected dependencies. Currently, it contains our Go SDK, the source codes of the language's standard library.

4. Running the Program

The best part is running the code and seeing the result. GoLand has an excellent and safe way to run a specific file.

Find the func main() function in the code editor. To its left, in the margins with line numbers (the so-called gutter), there is a green triangle ▶. Click on it and select Run 'go build tasker'.

The Run/Console window will open at the bottom, and you will see the result of the program's execution:

Let's analyze the output:

Service lines (gray lines with paths and the #gosetup tag) are environment variables that the IDE passes to the compiler for proper building.

Program output (plain text) is the result of your fmt.Println and fmt.Printf statements.

Exit code: Process finished with exit code 0. This is the final report from the operating system. According to the widely accepted standard, exit code 0 means that the program successfully executed all instructions and finished without errors. Any other code means that the program "crashed" during operation.

What happens when you click Run?

  1. Code compilation — the Go compiler (the go build command) reads your main.go and instantly builds a ready-to-use executable binary file from it in a temporary directory.
  2. Execution — the operating system runs this binary file, starting execution from func main().
  3. Output — the instructions are executed, and the result is displayed in the console window.

5. Alt + Enter and Keyboard Shortcuts

While working in GoLand, you will sometimes see gray hint text right in the editor or underlines under your code.

The shortcut Alt + Enter or Option + Enter on macOS is your main magic wand. If the IDE underlined code in red (error) or yellow (warning), place the cursor there and press these keys. The IDE won't just explain the problem; it will also suggest options for automatic fixes.

The IDE also supports many other shortcuts for navigation. You can check them out in the JetBrains documentation or directly in the menu: Help -> Keyboard Shortcuts PDF.

6. Common Mistakes

The illusion of a "frozen program"

If you write a function in your code to read data from the keyboard — fmt.Scan(&variable), when you run it, no text might appear in the console, and the cursor will just blink. It often seems like the IDE has frozen. In reality, the program is just waiting for input. Click inside the Run console window, type some text, and press Enter. The program will read it and continue working.

The "wrong" code runs (Run Configurations)

Every time you click the green triangle next to main(), the IDE creates a run configuration. If you changed the project but then clicked Run at the very top of the window, the previous configuration might run. To always run exactly the code you are currently editing, click the green triangle ▶ to the left of the desired func main() right in the editor.

Missing or misspelled func main()
If you forget to write func main() or name the function func myMain(), the program will not run, as the operating system won't find the starting point. Ensure that it is always named exactly main and is located in package main.

GOROOT not selected for the project
If, when creating the project, you accidentally skipped the step of selecting the SDK, trying to import basic packages (e.g., "fmt") will throw a "package not found" error. This is easily fixed through settings: File → Settings → Go → GOROOT, selecting the installed version 1.25 there.

Naming conventions and special characters in paths
Although modern operating systems are more tolerant of file names, the golden rule of development states: paths to projects should not contain non-Latin characters, letters with diacritics, spaces, or non-standard special characters, etc. Using localized folder names often leads to unpredictable compiler and system utility errors. Use only basic Latin letters and numbers. Furthermore, the Go ecosystem has its own naming standard: project and module names should be written in lowercase with short, clear words. If there are multiple words, they are usually separated by a hyphen like task-manager or written as one word like tasker. It is recommended to avoid uppercase letters and underscores in root project folder names.

1
Task
Go SELF, level 5, lesson 3
Locked
Package indices
Package indices
1
Task
Go SELF, level 5, lesson 3
Locked
Hunt for o
Hunt for o
1
Task
Go SELF, level 5, lesson 3
Locked
First hyphen
First hyphen
1
Task
Go SELF, level 5, lesson 3
Locked
Login validation
Login validation
Comments
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION