Skip to content

Control Structure on unpack #124

@urso

Description

@urso

Sometimes when unpacking we want to preserve the structure of original config, while mostly dedotting other settings. Sometimes we want full dedot and sometimes always a flattened list of keys. This means we have a great semantic variety which are not easy to express on unpack. This requires quite some amount of post-processing, only supporting a subset of required semantics.

  • Add an option to unpack preserving the original structure from the original config file when dedot is enabled
  • Add support via struct tags or interface/types to control when and how structure should be preserved for a sub-namespace.
  • Add support to always unpack flattened key/value pairs.

struct tag options to be introduced:
flatten:

When unpacking into a map we flatten all keys, so to create a flat list of key-value pairs

config.go

type config struct {
  Fields map[string]interface{} `config:"fields,flatten"`
}

config.yml

fields:
  a.b:1
  x:
    y:
      z: 2

will always unpack into:

map[string]interface{}{
  "a.b": 1,
  "x.y.z": 2,
}

preserve

Will always try to preserve the original structure from within the original config file/source:

config.go

type config struct {
  Fields map[string]interface{} `config:"fields,preserve"`
}

config.yml

fields:
  a.b:1
  x:
    y:
      z: 2

will always unpack into:

map[string]interface{}{
  "a.b": 1,
  "x": map[string]interface{}{
    "y": map[string]interface{}{
      "z": 2,
    },
  },
}

expand

Expand always splits names.

config.go

type config struct {
  Fields map[string]interface{} `config:"fields,expand"`
}

config.yml

fields:
  a.b:1
  x:
    y:
      z: 2

will always unpack into:

map[string]interface{}{
  "a": map[string]interface{}{
    b": 1,
  },
  "x": map[string]interface{}{
    "y": map[string]interface{}{
      "z": 2,
    },
  },
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions