Coder Social home page Coder Social logo

bellows's Introduction

bellows

Flatten and expand golang maps and structs

Features

There are some existing golang flatten/expand implementations, but they are targeted to specific use-cases, and none of them flatten Structs. This one doesn't do Slices, but the feature could be added.

This Flatten will skip parsing a Map that does not have a String as the index.

This Flatten recursively passes values as their original Interface, so it is simpler than implementations that rely on passing reflect.Value.

Usage

// Expand a dot-separated flat map into a nested map
func Expand(value map[string]interface{}) map[string]interface{} {}

// Expand a dot-separated flat map into a nested map, with a prefix
func ExpandPrefixed(value map[string]interface{}, prefix string) map[string]interface{} {}

// Expand a dot-separated flat map into an existing nested map, with a prefix
func ExpandPrefixedToResult(value map[string]interface{}, prefix string, result map[string]interface{}) {}

// Flatten a nested map into a dot-separated flat map
func Flatten(value interface{}) map[string]interface{} {}

// Flatten a nested map into a dot-separated flat map, with a prefix
func FlattenPrefixed(value interface{}, prefix string) map[string]interface{} {}

// Flatten a nested map into an existing dot-separated flat map, with a prefix
func FlattenPrefixedToResult(value interface{}, prefix string, m map[string]interface{}) {}

Examples

Used in an update to Viper, to normalize config values coming from nested (JSON) and flat (CLI flags, env vars) sources.

Other golang flatten/expand implementations

(C) Copyright 2015 doublerebel. MIT Licensed.

bellows's People

Contributors

doublerebel avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.