etcd-production-setup
etcd-production-setup copied to clipboard
add etcd-ca method to generate certs
for github.com/coreos/etcd-ca
Hi @jakubdyszkiewicz I never encounter this issue. Could you show your code execute result and terminal when extracting the environment variable?
In general, it's not possible.
Well... it is possible. Take a look:
Complete sample code:
package main
import (
"fmt"
"github.com/kelseyhightower/envconfig"
)
type Something struct {
User string `envconfig:"user"`
}
func main() {
something := Something{}
err := envconfig.Process("my_app", &something)
if err != nil {
panic(err)
}
fmt.Printf("Value is: %v", something.User)
}
terminal output
jakub.dyszkiewicz in /Users/jakub.dyszkiewicz/dev/sample-go
❯❯❯ echo $MY_APP_USER
jakub.dyszkiewicz in /Users/jakub.dyszkiewicz/dev/sample-go
❯❯❯ echo $USER
jakub.dyszkiewicz
jakub.dyszkiewicz in /Users/jakub.dyszkiewicz/dev/sample-go
❯❯❯ ./sample-go
Value is: jakub.dyszkiewicz
jakub.dyszkiewicz in /Users/jakub.dyszkiewicz/dev/sample-go
❯❯❯ set -gx MY_APP_USER other_user
jakub.dyszkiewicz in /Users/jakub.dyszkiewicz/dev/sample-go
❯❯❯ ./sample-go
Value is: other_user
It's wired. Could you push a PR with your case in unittest makes CI job help validate?
It's because CI is the role of neutral referee. If we have any issue happens in personal computer, the best solution is to add more test for this repo.
@jakubdyszkiewicz I ran into a similar issue and while investigating I found this is specifically triggered when using the envconfig
struct tag to specify the environment variable name. When using this tag it will fall back to the environment value specified even when using a prefix.
I believe this is the intended behavior based on this note in the README:
If envconfig can't find an environment variable in the form PREFIX_MYVAR, and there is a struct tag defined, it will try to populate your variable with an environment variable that directly matches the envconfig tag in your struct definition:
Here's a playground snippet demonstrating the difference: https://play.golang.org/p/KssTfMgXED1
import (
"fmt"
"os"
"github.com/kelseyhightower/envconfig"
)
type ImplicitTest struct {
User string
}
type ExplicitTest struct {
User string `envconfig:"USER"`
}
func main() {
os.Setenv("USER", "test")
implicitTest := ImplicitTest{}
envconfig.MustProcess("my_app", &implicitTest)
fmt.Printf("The value of ImplicitTest.User: \"%s\"\n", implicitTest.User)
explicitTest := ExplicitTest{}
envconfig.MustProcess("my_app", &explicitTest)
fmt.Printf("The value of ExplicitTest.User: \"%s\"\n", explicitTest.User)
}
output:
The value of ImplicitTest.User: ""
The value of ExplicitTest.User: "test"
Same problem here.
Hi. I think this PR is the complete solution. https://github.com/kelseyhightower/envconfig/pull/214
I realized that there is no way to fix this problem without partial backward compatibility break. This wrong (IMHO) behavior is the author's decision (it's obvious if you look at the unit tests). Using new 'no_pfx' tag is trade-off but quite fit solution. See second commit in my PR https://github.com/kelseyhightower/envconfig/pull/214