Local Development

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, or add --organization-id and --workspace-id flags as in the overview.

Running the Service

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

Reading Values

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 through Ennote. Every rebuild of your service inherits the variables:

ennote secret get "api-env" -- air

Tests

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

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

Saving the Command in a 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?

If you encounter any issues or have questions, don't hesitate to contact support. Our team is here to assist you with any challenges you might face.