---
title: "Local Development: Go"
description: "Run Go services locally with secrets from Ennote instead of a .env file: start go run, Air live reload or tests with ennote secret get and read the values with os.Getenv."
canonical_url: "https://docs.ennote.io/guides/local-development/go"
---
# Local Development: Go

> Run Go services locally with secrets from Ennote instead of a .env file: start go run, Air live reload or tests with ennote secret get and read the values with os.Getenv.

Put `ennote secret get "<secret>" --` in front of the command that starts your service. Go reads the values with `os.Getenv`, like any environment variable.

The examples use a secret named `api-env`. Set your organization and workspace once with [`ennote config set`](https://docs.ennote.io/cli/commands/config), or add `--organization-id` and `--workspace-id` flags as in the [overview](https://docs.ennote.io/guides/local-development/overview#sharing-the-command-with-your-team).

## Running the Service

```bash
ennote secret get "api-env" -- go run ./cmd/api
```

## Reading Values

```go [config.go]
package main

import (
    "log"
    "os"
)

func mustEnv(key string) string {
    v, ok := os.LookupEnv(key)
    if !ok || v == "" {
        log.Fatalf("missing required environment variable %s", key)
    }
    return v
}

var databaseURL = mustEnv("DATABASE_URL")
```

All values arrive as strings. Parse numbers and booleans with `strconv`. Libraries that read the environment, such as `caarlos0/env` or `kelseyhightower/envconfig`, work without changes.

## Live Reload With Air

Start [Air](https://github.com/air-verse/air) through Ennote. Every rebuild of your service inherits the variables:

```bash
ennote secret get "api-env" -- air
```

## Tests

Integration tests that need real credentials can run the same way:

```bash
ennote secret get "api-test-env" -- go test ./...
```

## Saving the Command in a Makefile

```makefile [Makefile]
ENNOTE = ennote secret get "api-env" --organization-id "my-org-id" --workspace-id "local-development" --

dev:
    $(ENNOTE) air

run:
    $(ENNOTE) go run ./cmd/api
```

## Keeping godotenv

If your code calls `godotenv.Load()`, you can leave it in place while you migrate. It does not override variables that are already set, so the values from Ennote win. It returns an error when no `.env` file exists, so ignore that error or remove the call once every developer uses Ennote.

<need-help>



</need-help>


## Sitemap

See the full [sitemap](https://docs.ennote.io/sitemap.md) for all pages.
