---
title: "koanf: MapKeys for natively typed maps in Go | VulCode"
description: "A fix in koanf, the Go configuration library: MapKeys now returns the keys of maps with a concrete type, such as map[string]int64, instead of an empty list."
url: "https://vulcode.com/en/opensource/contributions/koanf"
lang: "en"
---

[All contributions](https://vulcode.com/en/opensource/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.

[See the repository](https://github.com/knadh/koanf) [All contributions](https://vulcode.com/en/opensource/contributions)

- **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](https://github.com/knadh/koanf/pull/447)

## Merged change 1

- [#447 MapKeys returns an empty slice for a natively-typed map Merged 5 October 2026](https://github.com/knadh/koanf/pull/447)

## 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](https://vulcode.com/en/technologies/go)

## Other projects we write code for

- [**urfave/cli** Go · 24,329 stars A declarative Go package for building command line tools.](https://vulcode.com/en/opensource/contributions/urfave-cli)

- [**chezmoi** Go · 22,342 stars A dotfiles manager that keeps the same settings on many different machines, securely.](https://vulcode.com/en/opensource/contributions/chezmoi)

- [**goquery** Go · 14,995 stars A Go library for traversing and changing HTML documents in the style of jQuery, built on the golang.org/x/net/html parser.](https://vulcode.com/en/opensource/contributions/goquery)

- [**Ebitengine** Go · 13,647 stars A 2D game engine in Go, used in games released for computers, phones, browsers and consoles.](https://vulcode.com/en/opensource/contributions/ebiten)

- [**Fission** Go · 8,950 stars A serverless functions framework for Kubernetes that runs code as functions and scales them down to zero when they are idle.](https://vulcode.com/en/opensource/contributions/fission)

- [**Concourse** Go · 7,944 stars A container-based automation system written in Go and used mostly for CI/CD. Pipelines and tasks are described in YAML files.](https://vulcode.com/en/opensource/contributions/concourse)

## Describe your project.

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

### Rather skip the form?

Ask in the chat or write to us directly.

Open the chat

- **Email**: [hello@vulcode.com](mailto:hello@vulcode.com)
- **Phone**: [+48 576 043 920](tel:+48576043920)
- **Discord**: [discord.gg/vulcode](https://discord.gg/vulcode)
