Closed nccurry closed 6 years ago
The issue here is syntax. Multiple struct tags are separated by spaces, not commas.
package main
import (
"fmt"
"os"
"github.com/kelseyhightower/envconfig"
)
type backwordTag struct {
MyBool bool `default:"false" split_words:"true"`
}
type forwardTag struct {
MyBool bool `split_words:"true" default:"false"`
}
func main() {
var bt backwordTag
var ft forwardTag
os.Setenv("MY_BOOL", "true")
err := envconfig.Process("", &bt)
if err != nil {
fmt.Println("Backword Tag", err)
}
fmt.Printf("%t\n", bt.MyBool)
err = envconfig.Process("", &ft)
if err != nil {
fmt.Println("Forward Tag", err)
}
fmt.Printf("%t\n", ft.MyBool)
}
true
true
Ah! Good catch. Thanks
I noticed that the order of the struct tags is important and determines whether the split_words functionality words.
I didn't see this mentioned anywhere.