-
-
Notifications
You must be signed in to change notification settings - Fork 275
UseFieldNameByDefault doesn't support acronyms #295
Copy link
Copy link
Closed
Description
First of all, this is a great feature 🚀
Quick description of the issue
I have a field called HTTPVersion.
When using the UseFieldNameByDefault option, it translates it to H_TT_P_VERSION, when I expect it to be HTTP_VERSION.
A demo of the issue
basel@MM main1 % cat main.go
package main
import (
"fmt"
"github.com/caarlos0/env/v10"
"log"
)
type Config struct {
HTTPVersion string
}
func main() {
cfg := &Config{}
opts := env.Options{
UseFieldNameByDefault: true,
}
// Load env vars.
if err := env.ParseWithOptions(cfg, opts); err != nil {
log.Fatal(err)
}
// Print the loaded data.
fmt.Printf("%+v\n", cfg)
}
basel@MM main1 %
basel@MM main1 % go build -o app . && HTTP_VERSION=2.0 ./app
&{HTTPVersion:}
basel@MM main1 % go build -o app . && H_TT_P_VERSION=2.0 ./app
&{HTTPVersion:2.0}
basel@MM main1 % Suggestion
Looks like it comes down to toEnvName.
I've tried a quick, simple and efficient fix, which will preserve acronyms (i.e. it will translate it to HTTP_VERSION).
I'll be happy to open a PR in case it's relevant.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels