Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for map[string]interface{} #164

Open
dominiksimek opened this issue Jan 21, 2020 · 1 comment
Open

Support for map[string]interface{} #164

dominiksimek opened this issue Jan 21, 2020 · 1 comment

Comments

@dominiksimek
Copy link

Hi, current version supports decoding of environment variables into map[string]string type. It will be useful to have support also for map[string]interface{}. Following code shows that map[string]interface{} is not supported:

package main

import (
  "fmt"
  "github.com/kelseyhightower/envconfig"
  "log"
)

type Cfg struct {
  Host         string                 `yaml:"host"         envconfig:"HOST"`
  Port         int                    `yaml:"port"         envconfig:"PORT"`
  ExtraConfig1 map[string]string      `yaml:"extraConfig1" envconfig:"EXTRA_CONFIG_1"`
  ExtraConfig2 map[string]interface{} `yaml:"extraConfig2" envconfig:"EXTRA_CONFIG_2"`
}

func main() {
  var c Cfg
  if err := envconfig.Process("", &c); err != nil {
    log.Fatal(err)
  }
  fmt.Printf("%+v\n", c)
}

This program prints:

$ HOST=localhost PORT=8000 EXTRA_CONFIG_1="var1: 1, var2: 2" EXTRA_CONFIG_2="var1: 1, var2: 2" ./envcfg 
{Host:localhost Port:8000 ExtraConfig1:map[ var2: 2 var1: 1] ExtraConfig2:map[ var2:<nil> var1:<nil>]}

So values from ExtraConfig2 map are nil.

interface{} can be directly "converted" to desired type without parsing, so it will be nice to have support for this.

Thanks.

@broamski
Copy link

broamski commented May 1, 2020

I'm encountering the same issue. Any advice on this?

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

No branches or pull requests

2 participants