Skip to main content
Moderne OnlyThis recipe is proprietary to Moderne and runs on the Moderne platform or CLI — it isn’t part of the open-source catalog. Available with a Moderne subscription.Contact Sales

Add import

Recipe IDorg.openrewrite.golang.AddImport
Artifactorg.openrewrite.recipe:recipes-go

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

Single recipeOpenRewriteModerne Proprietary License
Try in PlatformTry this recipe in the Moderne platform. Not a user yet? You’ll get a no-setup demo environment, with nothing to install or configure.

Options

2 parameters
1 required1 optional
ParameterExampleTypeRequired
packagePathfmtStringRequired
The import path to add.
onlyIfReferencedBooleanOptional
When true, add the import only if some identifier in the file already references the package via type attribution.

Usage

Run this recipe

You will need to have configured the Moderne CLI on your machine before you can run the following command.

shell
mod run . --recipe AddImport --recipe-option "packagePath=fmt"

If the recipe is not available locally, then you can install it using:

mod config recipes jar install org.openrewrite.recipe:recipes-go:0.4.1