JetBrains Fleet 1.33 Help

Getting started with Go

This tutorial gets you up to speed with Go development in JetBrains Fleet. It covers the installation, project setup, and working with code.

Prerequisites

Download and install Fleet

  1. Download and install JetBrains Toolbox.

  2. In JetBrains Toolbox, click Install near the JetBrains Fleet icon.

    Download and install Fleet

Set up a workspace

Workspace is the directory where your project resides. It contains the project files and settings. You can open an existing project or start a new project by opening an empty directory.

In this tutorial we will walk through project setup from scratch.

Open a workspace

  1. Press ⌘ O or select File | Open from the menu.

  2. In the file browser, navigate to an empty folder where you want to store your code and click Open.

When you open a directory, it becomes the root of a workspace. You can view its contents in the Files view.

The Files view in the left panel

Create project files

  1. In the Files view, right-click the folder node, then select New File.

  2. Type the filename (for example, main.go) and press .

    Type or paste some code. You can use the following code snippet:

    package main func main() { println("Hello World") }

    Alternatively, in the editor, select Simple application. The Simple application option creates a file with an empty main function in the main package.

  3. In the Files view, right-click the folder node, then select New File.

  4. Type go.mod and press .

    Type or paste some code. You can use the following code snippet:

    module myGoApp go 1.17

Now we have to specify the project settings, such as the path to Go executable and so on.

Configuring Go SDK

In Smart mode, which will be covered later, JetBrains Fleet automatically detects a virtual environment and configures a Go SDK. If the automatic SDK detection fails, you can configure GOROOT manually.

Configuring Go SDK for the workspace

  1. Press ⌘ , and switch to the tab with the project settings:

    Workspace preferences tab
  2. In the Toolchains | GOROOT section, click the drop-down list, and do one of the following:

    • Select one of the detected Go SDK

    • Click Add Go Root, and then specify the path to the Go SDK directory.

    Selecting a Python interpreter for the workspace

Smart mode

You can use JetBrains Fleet as a smart text editor, rather than a full-fledged IDE. However, if you need code intelligence features, you can enable them by turning the Smart Mode on.

Enable smart mode

  • In the top-right corner of the window, click Smart Mode, then Enable.

    After you click the Enable button, you may have to wait for some time, while the backend is being prepared.

    Smart mode popup

Running your code

With Smart Mode enabled, you can run your project. For that, you can use a gutter icon in the editor, or you can create a run configuration that will allow you to fine-tune the way your application should be run.

Run from the editor

  • Navigate to the entry point of your application and click the run icon in the gutter. Select Run `go build <module_name>`.

    Using the gutter action

Another way to run a program is to use a run configuration. It allows you to customize the startup: specify Go tool arguments and flags, environment variables, and so on.

For example, in the following example we use runParams to pass command-line parameters to our program. For more information about run configuration parameters, refer to Go run configurations.

Create a run configuration

  1. Click the Run icon (⌘ R) and select Create Run Configurations in run.json.

  2. In the run.json file that opens, define running or debugging parameters. If the file is empty, press ⌥ ⏎ or click the file template link.

    Alternatively, paste and edit the following code:

    { "configurations": [ { "type": "go", "name": "findAverage", "goExecPath": "/usr/local/go/bin/go", "buildParams": [ "$PROJECT_DIR$/main.go", ], "runParams": ["1", "2", "3"] } ] }

    Modify the configuration properties according to your environment.

    For more information about run configuration parameters, refer to Go run configurations.

Launch a run configuration

  1. Click the Run icon (⌘ R) and select the configuration.

  2. Hover over the created run configuration and click Run.

Debugging your code

Broadly, debugging is the process of detecting and correcting errors in a program. You can run the debugging from the gutter of the editor or by using run.json. For a tutorial on debugging, refer to Debugging quickstart.

Each debugging process starts with setting a breakpoint.

Set a breakpoint

  • Click the gutter next to the line where you want to create a breakpoint.

    Set a breakpoint

Now we can proceed with debugging. As it was said, you can use the gutter icon or a run configuration.

Starting a debug session from the gutter

  1. Click the Run icon on the gutter.

  2. Select Debug `go build <configuration_name>.

    Starting a debug session from the editor

You can use run.json to configure the debugging process, the same approach we used in running your code.

Create a run configuration

  1. Click the Run icon (⌘ R) and select Create Run Configurations in run.json.

  2. In the run.json file that opens, define running or debugging parameters. If the file is empty, press ⌥ ⏎ or click the file template link.

    Alternatively, paste and edit the following code:

    { "configurations": [ { "type": "go", "name": "findAverage", "goExecPath": "/usr/local/go/bin/go", "buildParams": [ "$PROJECT_DIR$/main.go", ], "runParams": ["1", "2", "3"] } ] }

    Modify the configuration properties according to your environment.

    For more information about run configuration parameters, refer to Go run configurations.

Launch a run configuration

  1. Click the Run icon (⌘ R) and select the configuration.

  2. Hover over the created run configuration and click Debug.

Last modified: 15 April 2024