summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2022-07-31 14:01:57 -0600
committerLuke Shumaker <lukeshu@lukeshu.com>2022-07-31 14:01:57 -0600
commitd163b167496d914a00355a3f44897d0a43af96df (patch)
tree08af6c90ca8cdb48814e5681f813e3617c1b6aa0 /lib
parent326319cff84557e522b2ea8b21755b22764e85af (diff)
Ohh, go 1.18 added reflect.Value.fieldbyIndexErr
Diffstat (limited to 'lib')
-rw-r--r--lib/lowmemjson/encode.go15
1 files changed, 4 insertions, 11 deletions
diff --git a/lib/lowmemjson/encode.go b/lib/lowmemjson/encode.go
index 329f6c2..107b4da 100644
--- a/lib/lowmemjson/encode.go
+++ b/lib/lowmemjson/encode.go
@@ -189,20 +189,13 @@ func encode(w io.Writer, val reflect.Value, quote bool) {
case reflect.Struct:
encodeWriteByte(w, '{')
empty := true
- nextStructField:
for _, field := range indexStruct(val.Type()) {
- fVal := val
- for _, idx := range field.Path {
- if fVal.Kind() == reflect.Pointer {
- if fVal.IsNil() {
- continue nextStructField
- }
- fVal = fVal.Elem()
- }
- fVal = fVal.Field(idx)
+ fVal, err := val.FieldByIndexErr(field.Path)
+ if err != nil {
+ continue
}
if field.OmitEmpty && isEmptyValue(fVal) {
- continue nextStructField
+ continue
}
if !empty {
encodeWriteByte(w, ',')