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

Migrate from mitchellh/mapstructure to go-viper/mapstructure/v2

Recipe IDorg.openrewrite.golang.migration.MigrateToGoViperMapstructure
Artifactgithub.com/moderneinc/recipes-go

Migrate off github.com/mitchellh/mapstructure, unmaintained since 2023, to the community fork github.com/go-viper/mapstructure/v2. v2 keeps every function, hook and DecoderConfig field of v1 and adds more, so this is a path swap. The one exception is the exported Error struct, which v2 replaced with errors.Join; a file naming it is left untouched and reported by FindMapstructureErrorUsage. Run go mod tidy afterwards to sync go.sum.

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.

Usage​

Run this recipe

In order to run Go recipes, you will need to use the Moderne CLI. For Go specific configuration instructions, please see our configuring Go guide.

Once the CLI is installed, you can run the recipe via:

Run the recipe
mod run . --recipe MigrateToGoViperMapstructure

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

Installing without a pinned version lets mod config recipes upgrade pull in later versions without editing this command; a pinned version stays where you put it.

Install the recipe module
mod config recipes go install github.com/moderneinc/recipes-go