Skip to content

Upgrade koanf parsers/toml and providers/env to v2#6

Merged
bdk38 merged 2 commits intomainfrom
copilot/update-koanf-modules-to-v2
Mar 6, 2026
Merged

Upgrade koanf parsers/toml and providers/env to v2#6
bdk38 merged 2 commits intomainfrom
copilot/update-koanf-modules-to-v2

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 6, 2026

koanf restructured in v2, moving parsers and providers to separate modules with /v2 suffixes. The project was referencing the deprecated parsers/toml v0.1.0 and providers/env v1.1.0 paths, breaking TOML config parsing.

Changes

  • go.mod: Replace deprecated module paths with v2 equivalents (parsers/toml/v2 v2.2.0, providers/env/v2 v2.0.0); adds pelletier/go-toml/v2 v2.2.4 as transitive dep
  • internal/config/defaults.go and internal/config/config.go: Update import paths to /v2 variants
  • internal/config/config.go: Adapt env.Provider call to the new v2 API — signature changed from (prefix, delim string, fn func(string) string) to (delim string, opt env.Opt) with transform func now typed func(key, value string) (string, any):
// Before
env.Provider("HELLPOT_", ".", func(s string) string {
    ...
    return s
})

// After
env.Provider(".", env.Opt{
    Prefix: "HELLPOT_",
    TransformFunc: func(s, v string) (string, any) {
        ...
        return s, v
    },
})
Original prompt

Fix TOML Parser by Upgrading koanf Modules to v2

Problem

The TOML configuration parser is failing because we're using outdated koanf module paths. The koanf project restructured in v2, moving parsers and providers to separate modules with /v2 suffixes.

Root Cause

Our current go.mod references:

  • github.com/knadh/koanf/parsers/toml v0.1.0 (deprecated)
  • github.com/knadh/koanf/providers/env v1.1.0 (deprecated)

But koanf now uses:

  • github.com/knadh/koanf/parsers/toml/v2 (current)
  • github.com/knadh/koanf/providers/env/v2 (current)

Solution

1. Update go.mod

Change the module paths to include /v2:

// OLD paths - remove these
github.com/knadh/koanf/parsers/toml v0.1.0
github.com/knadh/koanf/providers/env v1.1.0

// NEW paths - use these
github.com/knadh/koanf/parsers/toml/v2 v2.2.4
github.com/knadh/koanf/providers/env/v2 v2.0.0

2. Update internal/config/defaults.go

Change the import path:

// OLD
import (
    // ... other imports
    "github.com/knadh/koanf/parsers/toml"
)

// NEW
import (
    // ... other imports
    "github.com/knadh/koanf/parsers/toml/v2"
)

Note: The usage of toml.Parser() remains the same - no code changes needed beyond the import.

3. Update internal/config/config.go

Change both import paths:

// OLD
import (
    // ... other imports
    "github.com/knadh/koanf/parsers/toml"
    "github.com/knadh/koanf/providers/env"
    // ... other imports
)

// NEW
import (
    // ... other imports
    "github.com/knadh/koanf/parsers/toml/v2"
    "github.com/knadh/koanf/providers/env/v2"
    // ... other imports
)

4. Fetch Dependencies

Run these commands to fetch the new v2 versions:

go get github.com/knadh/koanf/parsers/toml/v2@latest
go get github.com/knadh/koanf/providers/env/v2@latest

5. Clean Up Dependencies

Run go mod tidy to:

  • Update transitive dependencies (like pelletier/go-toml to v2)
  • Update golang.org/x/term and golang.org/x/sys to latest compatible versions
  • Remove any unused dependencies
  • Ensure go.sum is up-to-date

Expected Benefits

  • ✅ Fixes TOML configuration parsing issues
  • ✅ Uses actively maintained v2 modules
  • ✅ Upgrades to faster, more compliant TOML parser (pelletier/go-toml/v2)
  • ✅ Updates golang.org/x/* packages to latest versions
  • ✅ No functional API changes - fully backwards compatible

Testing

After changes:

  1. Build the project: go build
  2. Run tests: go test ./...
  3. Test config generation: ./hellpot -g
  4. Verify config loading works with existing TOML files

Notes

  • This is a low-risk upgrade - koanf v2 is designed for backwards compatibility
  • Only import paths change; no code logic changes required
  • The Parser API remains identical

This pull request was created from Copilot chat.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: bdk38 <244781262+bdk38@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix TOML parser by upgrading koanf modules to v2 Upgrade koanf parsers/toml and providers/env to v2 Mar 6, 2026
Copilot finished work on behalf of bdk38 March 6, 2026 17:40
@bdk38 bdk38 marked this pull request as ready for review March 6, 2026 17:42
@bdk38 bdk38 merged commit 6c9a029 into main Mar 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants