Skip to content

add toggle to split nats kv on "." delimiter#355

Merged
knadh merged 3 commits intoknadh:masterfrom
nickchomey:delim-nats-kv
May 29, 2025
Merged

add toggle to split nats kv on "." delimiter#355
knadh merged 3 commits intoknadh:masterfrom
nickchomey:delim-nats-kv

Conversation

@nickchomey
Copy link
Contributor

@nickchomey nickchomey commented Apr 26, 2025

This adds an optional "split" boolean config field to allow for splitting/unflattening a natskv key on the "." delimiter that denotes NATS KV subject/key hierarchies

My use case is:

Prefix = "abc"
There's a key "abc.xyz" with a value of "123"

Currently it will filter for keys with the "abc" prefix (minimizing kv.Get() calls), but then it just ends up setting { "abc.xyz" : 123 } in the koanf confmap.

This PR allows it to split the key so that the conf map gets updated with something like this (or whatever the proper nested map syntax is in go)

{
  "abc": {
    "xyz": 123
  }
}

Inspiration taken from the env provider (and surely many others do something similar)

I'm quite open to renaming the field to something other than Split, as well as changing its comment description

@nickchomey
Copy link
Contributor Author

@TECHNOFAB11 Perhaps you'll want to look at this, as the original contributor of the nats provider?

@TECHNOFAB11
Copy link
Contributor

Looks good, it's been a while since I've seen my NATS provider code and I actually expected it to unflatten the data, so it's definitely a good idea to add the option to do that :)

@nickchomey
Copy link
Contributor Author

nickchomey commented Apr 26, 2025

An alternative, since you expected it to unflatten already, is to just make this the default behavior and jot even have a config option. Though, that would unfortunately break people's code if they're using it...

@TECHNOFAB11
Copy link
Contributor

An alternative, since you expected it to unflatten already, is to just make this the default behavior and jot even have a config option. Though, that would unfortunately break people's code if they're using it...

Yeah probably best to not break existing code even though it would be the expected outcome. PR is fine as is :)

@nickchomey
Copy link
Contributor Author

Hey @knadh, I made the requested change. Does this seem ready to merge?

@knadh knadh merged commit 18f7b50 into knadh:master May 29, 2025
@knadh
Copy link
Owner

knadh commented May 29, 2025

@nickchomey sorry, I lost track of this. Tagged providers/nats/v0.2.0

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.

3 participants