github.com/chenfeining/golangci-lint@v1.0.2-0.20230730162517-14c6c67868df/test/testdata/errchkjson_no_exported.go (about) 1 //golangcitest:args -Eerrchkjson 2 //golangcitest:config_path testdata/configs/errchkjson_no_exported.yml 3 package testdata 4 5 import ( 6 "encoding/json" 7 ) 8 9 // JSONMarshalStructWithoutExportedFields contains a struct without exported fields. 10 func JSONMarshalStructWithoutExportedFields() { 11 var withoutExportedFields struct { 12 privateField bool 13 ExportedButOmittedField bool `json:"-"` 14 } 15 _, err := json.Marshal(withoutExportedFields) // want "Error argument passed to `encoding/json.Marshal` does not contain any exported field" 16 _ = err 17 } 18 19 // JSONMarshalStructWithNestedStructWithoutExportedFields contains a struct without exported fields. 20 func JSONMarshalStructWithNestedStructWithoutExportedFields() { 21 var withNestedStructWithoutExportedFields struct { 22 ExportedStruct struct { 23 privatField bool 24 } 25 } 26 _, err := json.Marshal(withNestedStructWithoutExportedFields) 27 _ = err 28 }