Skip to content

Commit

Permalink
Move inputoffset option to a hujson struct tag.
Browse files Browse the repository at this point in the history
Otherwise staticcheck gets angry at us.
  • Loading branch information
bradfitz committed Sep 24, 2020
1 parent b2e1dda commit dde312d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,10 @@ func typeFields(t reflect.Type) structFields {
if !isValidTag(name) {
name = ""
}

hutag := sf.Tag.Get("hujson")
_, huOpts := parseTag(hutag)

index := make([]int, len(f.index)+1)
copy(index, f.index)
index[len(f.index)] = i
Expand All @@ -1154,7 +1158,7 @@ func typeFields(t reflect.Type) structFields {
}
}

isInputOffset := opts.Contains("inputoffset") && ft.Kind() == reflect.Int64
isInputOffset := huOpts.Contains("inputoffset") && ft.Kind() == reflect.Int64

// Record found field and index sequence.
if name != "" || !sf.Anonymous || ft.Kind() != reflect.Struct || isInputOffset {
Expand Down
2 changes: 1 addition & 1 deletion hujson_decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestHuDecode(t *testing.T) {

type ACL struct {
Action string
ByteOffset int64 `json:",inputoffset"`
ByteOffset int64 `hujson:",inputoffset"`
}

type ACLFile struct {
Expand Down

0 comments on commit dde312d

Please sign in to comment.