Skip to content

Commit

Permalink
Omit unexported fields from xml encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
Renier Morales committed Oct 26, 2016
1 parent a918969 commit 79afb71
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ func encodeStruct(value reflect.Value) ([]byte, error) {
fieldVal := val.FieldByName(f.Name)
fieldValKind := fieldVal.Kind()

// Omit unexported fields
if !fieldVal.CanInterface() {
continue
}

// Omit fields who are structs that contain no fields themselves
if fieldValKind == reflect.Struct && fieldVal.NumField() == 0 {
continue
Expand Down

0 comments on commit 79afb71

Please sign in to comment.