Giter Site home page Giter Site logo

Comments (8)

iamolegga avatar iamolegga commented on June 15, 2024 1

@jguttman94 as I've said before in your PR, everything looks good, but there is only one bug with map. Could you please check this branch and maybe help to fix that?

from enviper.

iamolegga avatar iamolegga commented on June 15, 2024 1

Thanks for the investigation @jguttman94

Let's move forward then and I'll change the test case for only env variables without config file to pass tests. Anyway, I believe this will work for 90% of usage and as you've said we can simply open a new issue for that.

from enviper.

iamolegga avatar iamolegga commented on June 15, 2024 1

Just made a release v1.3.0 with basic support of unmarshaling only from env vars, and opened an issue for map #9

from enviper.

jguttman94 avatar jguttman94 commented on June 15, 2024 1

Thanks for the release, @iamolegga. Just verified it works within my cobra CLI!

from enviper.

iamolegga avatar iamolegga commented on June 15, 2024

Hi, thanks for reporting. I'll try to find some time to check this

from enviper.

jguttman94 avatar jguttman94 commented on June 15, 2024

any news on this @iamolegga?

from enviper.

jguttman94 avatar jguttman94 commented on June 15, 2024

@iamolegga, took a stab at a fix on this. Let me know what your thoughts are!

from enviper.

jguttman94 avatar jguttman94 commented on June 15, 2024

@iamolegga, I took a look, and I'll be honest, I'm struggling with this one...

I believe this to be a separate issue that is more challenging to address. The issue with the unmarshalling of the pointers was easier to solve as the reflection used in the recursive loop over the raw configuration value just needed knowledge of a new pointer element. With that provided, and without mutating the original raw config value, the rest of the recursion loop was able to successfully destructure the environment variable into the pointer.

For the maps, it's a little different. It's easy enough to create a new map if the raw config value is nil, but the rest of the logic is dependent on iterating over each provided map value and recursively invoking bindEnvs. However, because we need to create a new instance of the map, there are no values to iterate over; that isn't known until bindEnvs returns and e.Viper.Unmarshal is invoked.

I may need some extra support on this one, as I'm quite new to golang reflection.

Here is some example code I was playing around with to create a new map in bindEnvs:

case reflect.Map:
  if fv.IsNil() {
    var mapType = reflect.MapOf(fv.Type().Key(), fv.Type().Elem())
    fv = reflect.MakeMap(mapType)
  }
  iter := fv.MapRange()
  for iter.Next() { // failing to destructure here, as the new map is empty, and we do not know the potential contents at this time
    if key, ok := iter.Key().Interface().(string); ok {
      e.bindEnvs(iter.Value().Interface(), append(prev, tv, key)...)
    }
  }

from enviper.

Related Issues (6)

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.