All contributions

knadh/koanf

koanf

A lightweight Go configuration library for JSON, TOML, YAML, environment variables, flags and other sources. It is used as an alternative to Viper.

Language
Go
GitHub stars
4,244
Merged changes
1

What we changed

MapKeys now returns the keys of a map with a concrete type, such as map[string]int64, instead of an empty list.

What this work shows

  • Reflection in Go (the reflect package)
  • Type assertions and map types in Go
  • Public library API contracts
What was broken

MapKeys returned nothing for a populated map

Set() or a provider such as structs can put a map with a concrete type, such as map[string]int64, into the config. MapKeys only checked for map[string]any, so for such a map it returned an empty list, although Get() returned it with all its keys.

How we fixed it

Keys from any map with string keys

When the value is not a map[string]any, MapKeys reads the keys through reflection and accepts any map with string keys. The result is still sorted, and a new test covers a map[string]int64.

#447

Merged change 1

  1. #447 MapKeys returns an empty slice for a natively-typed map Merged 5 October 2026

What it taught us

The most dangerous contract violation is the silent one: a function returns an empty result instead of data for valid input. We fix it in general, through reflection, instead of listing every possible map type.

More about this technology: Golang

Other projects we write code for

Describe your project.

A free quote comes back within an hour during working hours.