← All recipes
Moderne licensed

Add import

Recipe IDorg.openrewrite.golang.AddImportArtifactgithub.com/moderneinc/recipes-go

Add an import statement to a Go compilation unit. No-op if the import is already present in a compatible form.

Single recipeProprietary

Usage

You’ll need the Moderne CLI configured before running the command below.

mod run . --recipe org.openrewrite.golang.AddImport --recipe-option "packagePath=fmt"

If the recipe isn’t available locally, install it with:

mod config recipes go install github.com/moderneinc/recipes-go

Options

NameTypeDescription
packagePathrequiredStringThe import path to add.
e.g. fmt
onlyIfReferencedBooleanWhen true, add the import only if some identifier in the file already references the package via type attribution.