Go

This guide will show you how to integrate the Doppler CLI into your Go application development and debugging workflow inside Visual Studio Code.

Prerequisites

Setup

Ensure you've authenticated the Doppler CLI so secrets can be accessed from your machine:

doppler login

Then configure the Doppler CLI to select which project and environment to fetch secrets from by running the following command from a terminal within Visual Studio Code:

doppler setup

Launch Configuration

Unfortunately, the VS Code Go extension doesn't support modifying the command that's used to execute the debugger, so it's impossible to prefix that command with doppler run on a per-project basis. On the upside, you can still get the debugger using your secrets fairly easily by wrapping the dlv command used by the GoLang debugger.

Create the wrapper script

Create a new bash script named dlv-wrapper somewhere that's in your shell's PATH (e.g., /usr/local/bin). The script should look something like this:

#!/bin/bash

doppler_project=$(doppler configure get project --plain)
doppler_config=$(doppler configure get config --plain)

if [ "$doppler_project" != "" ] && [ "$doppler_config" != "" ]
then
  doppler run --no-check-version --forward-signals -- dlv "$@"
else
  echo "Doppler project and/or config not configured, using dlv without doppler..."
  dlv "$@"
fi

This script checks to see if a Doppler project and config has been configured for your project directory (i.e., what you do when you run doppler setup). If it sees that those have been configured, then it wraps the dlv command with doppler run. If it doesn't see those configured, it executes dlv without the Doppler CLI.

Update your User Settings

Open your User Settings by pressing cmd-shift-p (MacOS) or ctrl-shift-p (Windows) and typing "User Settings JSON". That will open up your user-level settings.json file. Add the following to it:

  "go.alternateTools": {
    "dlv": "/usr/local/bin/dlv-wrapper"
  },

Now, all your Go projects will use this wrapper script when executing the debugger.

If you'd rather make this workspace-specific, you can do so by saving the wrapper script to a bin subdirectory of your project and then editing your Workspace Settings JSON instead. You would add the following in that case:

{
  "go.alternateTools": {
    "dlv": "${workspaceFolder}/bin/dlv-wrapper"
  }
}

👍

Awesome Work!

Now you know how to inject Doppler secrets into your Go applications when developing with Visual Studio Code.