ignore fields with "-" tag name when decoding struct
This commit is contained in:
parent
9a905a34e6
commit
6ffac0df10
@ -517,6 +517,12 @@ func (d *decoder) decodeStruct(name string, node ast.Node, result reflect.Value)
|
||||
structType := structVal.Type()
|
||||
for i := 0; i < structType.NumField(); i++ {
|
||||
fieldType := structType.Field(i)
|
||||
tagParts := strings.Split(fieldType.Tag.Get(tagName), ",")
|
||||
|
||||
// Ignore fields with tag name "-"
|
||||
if tagParts[0] == "-" {
|
||||
continue
|
||||
}
|
||||
|
||||
if fieldType.Anonymous {
|
||||
fieldKind := fieldType.Type.Kind()
|
||||
@ -531,7 +537,6 @@ func (d *decoder) decodeStruct(name string, node ast.Node, result reflect.Value)
|
||||
// We have an embedded field. We "squash" the fields down
|
||||
// if specified in the tag.
|
||||
squash := false
|
||||
tagParts := strings.Split(fieldType.Tag.Get(tagName), ",")
|
||||
for _, tag := range tagParts[1:] {
|
||||
if tag == "squash" {
|
||||
squash = true
|
||||
|
@ -406,9 +406,12 @@ func TestDecode_flatMap(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDecode_structure(t *testing.T) {
|
||||
type Embedded interface{}
|
||||
|
||||
type V struct {
|
||||
Key int
|
||||
Foo string
|
||||
Embedded `hcl:"-"`
|
||||
Key int
|
||||
Foo string
|
||||
}
|
||||
|
||||
var actual V
|
||||
|
Loading…
Reference in New Issue
Block a user