GoLand 2019.2 Help

Quick start guide

This Quick start guide will introduce you the key concepts and help you with your first steps in GoLand.

Step 1. Open or create a project in GoLand

After you have installed GoLand and launched it for the first time, you need to create a project. Everything you do in GoLand is done within the context of a project. It serves as a basis for coding assistance, bulk refactoring, coding style consistency, and other features.

You have three options to start working on a project inside the IDE:

Open an existing project

To open a project that you store on your computer, click Open Project. In the file browser, navigate to a folder with project files and click Open.

After you have opened your project, you need to specify the location of the Go SDK. You can specify a local path to the SDK or download it. To set the Go SDK, open settings Ctrl+Alt+S and navigate to Go | GOROOT. Click the Add SDK button (the Add SDK button) near the GOROOT field and select between two options:

  • Local: use a local SDK copy. In the file browser, navigate to the SDK version that is on your hard drive.

  • Download: download the SDK. In the Target directory field, specify the path for the SDK. To use a file browser, click the Browse icon the Browse icon. Click OK.

Welcome screen

Clone an existing project from a Version Control System

You can also download sources from a VCS storage or repository. Click Check out from Version Control and select between Git (GitHub) or Mercurial:

  • To сheck out files from GitHub, click Log in to GitHub to enter your credentials. Enter a path to the sources and clone the repository to your computer.

  • To сheck out files from Mercurial, install and configure Mercurial and restart GoLand. Enter a path to the sources and clone the repository to your computer.

After you have opened your project, you need to specify the location of the Go SDK. You can specify a local path to the SDK or download it. To set the Go SDK, open settings Ctrl+Alt+S and navigate to Go | GOROOT. Click the Add SDK button (the Add SDK button) near the GOROOT field and select between two options:

  • Local: use a local SDK copy. In the file browser, navigate to the SDK version that is on your hard drive.

  • Download: download the SDK. In the Target directory field, specify the path for the SDK. To use a file browser, click the Browse icon the Browse icon. Click OK.

Clone a repository

For more information about version control systems, see Version control.

Create a new project

  1. To create a project, perform one of the following actions:

  2. In the New Project dialog, select Go.

  3. In the GOROOT field, specify the Go SDK. You can select a local copy of SDK or download it.

    • To select a local copy of the Go SDK, click the Add SDK icon (the Add SDK icon) near the GOROOT field and select Local. In the file browser, navigate to the SDK version that is on your hard drive.

    • To download the Go SDK, click the Add SDK icon (the Add SDK icon) near the GOROOT field and select Download. From the Version list, select the SDK version. In the Target directory field, specify the path for the SDK. To use a file browser, click the Browse icon the Browse icon. Click OK.

  4. Click Create.

Download Go SDK

Create a Go file

A new project has no Go files. To create a Go file, perform one of the following actions:

  • Right-click the parent folder of a project, and select New | Go File.

  • Click the parent folder of a project, press Alt+Insert, and select Go File.

  • Click the parent folder of a project, navigate to File | New | Go File.

In the New Go File dialog, type a name of the file and select whether you want to create an empty Go file (Empty file) or a Go file with the defined main function (Simple Application).

Create a Go file

Step 2. Explore the user interface

When you launch GoLand for the very first time, you see the Welcome screen dialog. From the Welcome screen dialog, you can create and open projects, check out a project from a version control system, view documentation, and configure the IDE.

When a project is opened, you see the main window divided into several logical areas.

Project view, Editor, and Tool Windows
  1. The Project tool window, which is on the left side, displays your project files. Tool windows are windows that provide access to project management, search, running and debugging, integration with version control systems, and other tasks. To see a list of all tool windows, navigate to View | Tool Windows.

  2. The Editor pane is on the right side, where you write your code. It has tabs for easy navigation between open files.

  3. The navigation bar is above the editor additionally allows you to quickly run and debug your application as well as do basic VCS actions.

  4. The Left gutter is the vertical stripe next to the editor. It shows you the breakpoints and provides a convenient way to navigate to a definition or a declaration. Also, you can use the Run Application icon (the Run Application icon) to run or to debug your application.

  5. The Right gutter, on the right side of the editor. GoLand monitors the quality of your code and shows the results of code inspections: errors, warnings, typos, and other issues. The indicator at the top of the gutter shows the overall status of code inspections for the entire file.

  6. The status bar indicates the status of your project and the entire IDE and shows you information about a file encoding, line separators, inspection profiles, and other warnings and information messages.

In the lower left part of the IDE, in the Status bar, you can see Show tool window bars or Hide tool window                 bars buttons. These buttons toggle the display of the tool window popup. If you hover your mouse pointer over this button, the list of the currently available tool windows shows up.

Quick access to tool windows

Step 3. Write your code

As you work in the editor, GoLand analyzes your code, searches for ways to optimize it, and detects potential and actual problems. The following list includes basic features and tools that might be useful for your code writing and increase your productivity:

Code completion

GoLand has two types of code completion:

Basic code completion Ctrl+Space helps you complete names of types, interfaces, methods, and keywords within the visibility scope. When you invoke code completion, GoLand analyzes the context and suggests the choices that are reachable from the current caret position. By default, GoLand displays the code completion popup automatically as you type.

Smart code completion Ctrl+Shift+Space filters the suggestions list and shows only the types applicable to the current context.

The following animation shows the difference between basic and smart completion. Notice the number of variants that are suggested for different completion types

Generating code

GoLand provides multiple ways to generate common code constructs and recurring elements, which helps you increase productivity. These can be either predefined or custom templates, which are applied differently based on the context, various wrappers, and automatic pairing of characters.

From the main menu, select Code | Generate Alt+Insert to open the popup menu with available constructs that you can generate.

You can generate getters, setters, constructors, missing methods, and test files. For more information about the Generate action, see Using the Generate action.

Live templates

By using live templates, you can insert frequently-used constructions into your code. For example, loops, conditions, various declarations, or print statements.

To expand a code snippet, type the corresponding template abbreviation and press Tab. Keep pressing Tab to jump from one variable in the template to the next one. Press Shift+Tab to move to the previous variable.

To see the list of live templates, open settings Ctrl+Alt+S and navigate to Editor | Live templates.

Consider the following example of the Hello World program that is coded with Live Templates.

Inspections

In GoLand, there is a set of code inspections that detect and correct anomalous code in your project before you compile it. The IDE can find and highlight various problems, locate dead code, find probable bugs, spelling problems, and improve the overall code structure.

Inspections can scan your code in all project files, or only in specific scopes (for example, only in production code, or in modified files).

Every inspection has a severity level — the extent to which a problem can affect your code. Severities are highlighted differently in the editor so that you can quickly distinguish between critical problems and less important things. GoLand comes with a set of predefined severity levels and enables you to create your own.

To see the list of inspections, open settings Ctrl+Alt+S and navigate to Editor | Inspections. Disable some of them, or enable others, plus adjust the severity of each inspection. You decide whether it should be considered an error or just a warning.

For example, the Unreachable code inspection detects parts of code that cannot be executed.

The unreachable code inspection

Intention actions

As you work in the editor, GoLand analyzes your code, searches for ways to optimize it, and detects potential and actual problems. Intention actions cover a wide range of situations from errors and warnings to optimization suggestions.

In GoLand, you can use the following types of intention actions:

  • Intention actions yellow bulb icon: an action that generates a piece of code or suggests an alternative variant for your code. Usually, an intention action is applied to a valid piece of code. By clicking the yellow bulb icon, you can view intention actions available in the current context. For example, you can create a constructor that generates values of a struct type. Or, replace the if-else statement with the equivalent one but with a negated condition and swapped if-else branches.

  • Quick-fixes red bulb icon: an action that suggests a solution for a problem in your code. Usually, the intention action is applied to a code that has an error. For example, when you missed brackets at the end of the expression. Or, when you forgot to convert a value to a specific type.

To see the list of intention actions, open settings Ctrl+Alt+S and navigate to Editor | Intentions.

  1. To apply an intention action, click the bulb icon (or press Alt+Enter) to open the list of suggestions.

  2. Select an action from the list and press Enter.

    For example, you can use an intention action to inject another language in your code:

Step 4. Run and debug your code

You can run and debug your code in GoLand from a keyboard, from the context menu, from the gutter menu, or by using the Run/Debug configuration.

Run your code

To run your application Shift+F10, click the Run Application icon Run and select Run <application_name>.

Run your code from the gutter

Debug your code

Debugging starts with placing breakpoints at which program execution will be suspended so that you can explore program data. Just click the line in the left gutter where you want to place a breakpoint.

To debug your application Shift+F9, click the Run Application icon Run and select Debug <application_name>. Then go through the program execution step by step (see the available options in the Run menu or the Debug tool window).

Refer to the section Debugging for details.

Debug your code
Last modified: 21 August 2019