Handle struct field name variations
This commit is contained in:
+4
-1
@@ -9,7 +9,8 @@ type Kind int
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
// meta
|
// meta
|
||||||
Comment Kind = iota
|
Invalid Kind = iota
|
||||||
|
Comment
|
||||||
Key
|
Key
|
||||||
|
|
||||||
// top level structures
|
// top level structures
|
||||||
@@ -34,6 +35,8 @@ const (
|
|||||||
|
|
||||||
func (k Kind) String() string {
|
func (k Kind) String() string {
|
||||||
switch k {
|
switch k {
|
||||||
|
case Invalid:
|
||||||
|
return "Invalid"
|
||||||
case Comment:
|
case Comment:
|
||||||
return "Comment"
|
return "Comment"
|
||||||
case Key:
|
case Key:
|
||||||
|
|||||||
+6
-2
@@ -3,6 +3,7 @@ package toml
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type target interface {
|
type target interface {
|
||||||
@@ -358,8 +359,11 @@ func scopeStruct(v reflect.Value, name string) (target, bool, error) {
|
|||||||
if f.Anonymous {
|
if f.Anonymous {
|
||||||
// TODO: handle embedded structs
|
// TODO: handle embedded structs
|
||||||
} else {
|
} else {
|
||||||
// TODO: handle names variations
|
fieldName, ok := f.Tag.Lookup("toml")
|
||||||
if f.Name == name {
|
if !ok {
|
||||||
|
fieldName = f.Name
|
||||||
|
}
|
||||||
|
if strings.EqualFold(fieldName, name) {
|
||||||
return valueTarget(v.Field(i)), true, nil
|
return valueTarget(v.Field(i)), true, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user