2017-11-20 09:30:52 -05:00
|
|
|
package jsoniter
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2018-07-25 04:17:02 -04:00
|
|
|
"github.com/modern-go/reflect2"
|
2017-11-20 09:30:52 -05:00
|
|
|
"reflect"
|
|
|
|
"sort"
|
|
|
|
"strings"
|
|
|
|
"unicode"
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
|
|
|
var typeDecoders = map[string]ValDecoder{}
|
|
|
|
var fieldDecoders = map[string]ValDecoder{}
|
|
|
|
var typeEncoders = map[string]ValEncoder{}
|
|
|
|
var fieldEncoders = map[string]ValEncoder{}
|
|
|
|
var extensions = []Extension{}
|
|
|
|
|
|
|
|
// StructDescriptor describe how should we encode/decode the struct
|
|
|
|
type StructDescriptor struct {
|
2018-07-25 04:17:02 -04:00
|
|
|
Type reflect2.Type
|
|
|
|
Fields []*Binding
|
2017-11-20 09:30:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetField get one field from the descriptor by its name.
|
|
|
|
// Can not use map here to keep field orders.
|
|
|
|
func (structDescriptor *StructDescriptor) GetField(fieldName string) *Binding {
|
|
|
|
for _, binding := range structDescriptor.Fields {
|
2018-07-25 04:17:02 -04:00
|
|
|
if binding.Field.Name() == fieldName {
|
2017-11-20 09:30:52 -05:00
|
|
|
return binding
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Binding describe how should we encode/decode the struct field
|
|
|
|
type Binding struct {
|
|
|
|
levels []int
|
2018-07-25 04:17:02 -04:00
|
|
|
Field reflect2.StructField
|
2017-11-20 09:30:52 -05:00
|
|
|
FromNames []string
|
|
|
|
ToNames []string
|
|
|
|
Encoder ValEncoder
|
|
|
|
Decoder ValDecoder
|
|
|
|
}
|
|
|
|
|
|
|
|
// Extension the one for all SPI. Customize encoding/decoding by specifying alternate encoder/decoder.
|
|
|
|
// Can also rename fields by UpdateStructDescriptor.
|
|
|
|
type Extension interface {
|
|
|
|
UpdateStructDescriptor(structDescriptor *StructDescriptor)
|
2018-07-25 04:17:02 -04:00
|
|
|
CreateMapKeyDecoder(typ reflect2.Type) ValDecoder
|
|
|
|
CreateMapKeyEncoder(typ reflect2.Type) ValEncoder
|
|
|
|
CreateDecoder(typ reflect2.Type) ValDecoder
|
|
|
|
CreateEncoder(typ reflect2.Type) ValEncoder
|
|
|
|
DecorateDecoder(typ reflect2.Type, decoder ValDecoder) ValDecoder
|
|
|
|
DecorateEncoder(typ reflect2.Type, encoder ValEncoder) ValEncoder
|
2017-11-20 09:30:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// DummyExtension embed this type get dummy implementation for all methods of Extension
|
|
|
|
type DummyExtension struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
// UpdateStructDescriptor No-op
|
|
|
|
func (extension *DummyExtension) UpdateStructDescriptor(structDescriptor *StructDescriptor) {
|
|
|
|
}
|
|
|
|
|
2018-07-25 04:17:02 -04:00
|
|
|
// CreateMapKeyDecoder No-op
|
|
|
|
func (extension *DummyExtension) CreateMapKeyDecoder(typ reflect2.Type) ValDecoder {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// CreateMapKeyEncoder No-op
|
|
|
|
func (extension *DummyExtension) CreateMapKeyEncoder(typ reflect2.Type) ValEncoder {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-11-20 09:30:52 -05:00
|
|
|
// CreateDecoder No-op
|
2018-07-25 04:17:02 -04:00
|
|
|
func (extension *DummyExtension) CreateDecoder(typ reflect2.Type) ValDecoder {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// CreateEncoder No-op
|
|
|
|
func (extension *DummyExtension) CreateEncoder(typ reflect2.Type) ValEncoder {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// DecorateDecoder No-op
|
|
|
|
func (extension *DummyExtension) DecorateDecoder(typ reflect2.Type, decoder ValDecoder) ValDecoder {
|
|
|
|
return decoder
|
|
|
|
}
|
|
|
|
|
|
|
|
// DecorateEncoder No-op
|
|
|
|
func (extension *DummyExtension) DecorateEncoder(typ reflect2.Type, encoder ValEncoder) ValEncoder {
|
|
|
|
return encoder
|
|
|
|
}
|
|
|
|
|
|
|
|
type EncoderExtension map[reflect2.Type]ValEncoder
|
|
|
|
|
|
|
|
// UpdateStructDescriptor No-op
|
|
|
|
func (extension EncoderExtension) UpdateStructDescriptor(structDescriptor *StructDescriptor) {
|
|
|
|
}
|
|
|
|
|
|
|
|
// CreateDecoder No-op
|
|
|
|
func (extension EncoderExtension) CreateDecoder(typ reflect2.Type) ValDecoder {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// CreateEncoder get encoder from map
|
|
|
|
func (extension EncoderExtension) CreateEncoder(typ reflect2.Type) ValEncoder {
|
|
|
|
return extension[typ]
|
|
|
|
}
|
|
|
|
|
|
|
|
// CreateMapKeyDecoder No-op
|
|
|
|
func (extension EncoderExtension) CreateMapKeyDecoder(typ reflect2.Type) ValDecoder {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// CreateMapKeyEncoder No-op
|
|
|
|
func (extension EncoderExtension) CreateMapKeyEncoder(typ reflect2.Type) ValEncoder {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// DecorateDecoder No-op
|
|
|
|
func (extension EncoderExtension) DecorateDecoder(typ reflect2.Type, decoder ValDecoder) ValDecoder {
|
|
|
|
return decoder
|
|
|
|
}
|
|
|
|
|
|
|
|
// DecorateEncoder No-op
|
|
|
|
func (extension EncoderExtension) DecorateEncoder(typ reflect2.Type, encoder ValEncoder) ValEncoder {
|
|
|
|
return encoder
|
|
|
|
}
|
|
|
|
|
|
|
|
type DecoderExtension map[reflect2.Type]ValDecoder
|
|
|
|
|
|
|
|
// UpdateStructDescriptor No-op
|
|
|
|
func (extension DecoderExtension) UpdateStructDescriptor(structDescriptor *StructDescriptor) {
|
|
|
|
}
|
|
|
|
|
|
|
|
// CreateMapKeyDecoder No-op
|
|
|
|
func (extension DecoderExtension) CreateMapKeyDecoder(typ reflect2.Type) ValDecoder {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// CreateMapKeyEncoder No-op
|
|
|
|
func (extension DecoderExtension) CreateMapKeyEncoder(typ reflect2.Type) ValEncoder {
|
2017-11-20 09:30:52 -05:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-07-25 04:17:02 -04:00
|
|
|
// CreateDecoder get decoder from map
|
|
|
|
func (extension DecoderExtension) CreateDecoder(typ reflect2.Type) ValDecoder {
|
|
|
|
return extension[typ]
|
|
|
|
}
|
|
|
|
|
2017-11-20 09:30:52 -05:00
|
|
|
// CreateEncoder No-op
|
2018-07-25 04:17:02 -04:00
|
|
|
func (extension DecoderExtension) CreateEncoder(typ reflect2.Type) ValEncoder {
|
2017-11-20 09:30:52 -05:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// DecorateDecoder No-op
|
2018-07-25 04:17:02 -04:00
|
|
|
func (extension DecoderExtension) DecorateDecoder(typ reflect2.Type, decoder ValDecoder) ValDecoder {
|
2017-11-20 09:30:52 -05:00
|
|
|
return decoder
|
|
|
|
}
|
|
|
|
|
|
|
|
// DecorateEncoder No-op
|
2018-07-25 04:17:02 -04:00
|
|
|
func (extension DecoderExtension) DecorateEncoder(typ reflect2.Type, encoder ValEncoder) ValEncoder {
|
2017-11-20 09:30:52 -05:00
|
|
|
return encoder
|
|
|
|
}
|
|
|
|
|
|
|
|
type funcDecoder struct {
|
|
|
|
fun DecoderFunc
|
|
|
|
}
|
|
|
|
|
|
|
|
func (decoder *funcDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) {
|
|
|
|
decoder.fun(ptr, iter)
|
|
|
|
}
|
|
|
|
|
|
|
|
type funcEncoder struct {
|
|
|
|
fun EncoderFunc
|
|
|
|
isEmptyFunc func(ptr unsafe.Pointer) bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func (encoder *funcEncoder) Encode(ptr unsafe.Pointer, stream *Stream) {
|
|
|
|
encoder.fun(ptr, stream)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (encoder *funcEncoder) IsEmpty(ptr unsafe.Pointer) bool {
|
|
|
|
if encoder.isEmptyFunc == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return encoder.isEmptyFunc(ptr)
|
|
|
|
}
|
|
|
|
|
|
|
|
// DecoderFunc the function form of TypeDecoder
|
|
|
|
type DecoderFunc func(ptr unsafe.Pointer, iter *Iterator)
|
|
|
|
|
|
|
|
// EncoderFunc the function form of TypeEncoder
|
|
|
|
type EncoderFunc func(ptr unsafe.Pointer, stream *Stream)
|
|
|
|
|
|
|
|
// RegisterTypeDecoderFunc register TypeDecoder for a type with function
|
|
|
|
func RegisterTypeDecoderFunc(typ string, fun DecoderFunc) {
|
|
|
|
typeDecoders[typ] = &funcDecoder{fun}
|
|
|
|
}
|
|
|
|
|
|
|
|
// RegisterTypeDecoder register TypeDecoder for a typ
|
|
|
|
func RegisterTypeDecoder(typ string, decoder ValDecoder) {
|
|
|
|
typeDecoders[typ] = decoder
|
|
|
|
}
|
|
|
|
|
|
|
|
// RegisterFieldDecoderFunc register TypeDecoder for a struct field with function
|
|
|
|
func RegisterFieldDecoderFunc(typ string, field string, fun DecoderFunc) {
|
|
|
|
RegisterFieldDecoder(typ, field, &funcDecoder{fun})
|
|
|
|
}
|
|
|
|
|
|
|
|
// RegisterFieldDecoder register TypeDecoder for a struct field
|
|
|
|
func RegisterFieldDecoder(typ string, field string, decoder ValDecoder) {
|
|
|
|
fieldDecoders[fmt.Sprintf("%s/%s", typ, field)] = decoder
|
|
|
|
}
|
|
|
|
|
|
|
|
// RegisterTypeEncoderFunc register TypeEncoder for a type with encode/isEmpty function
|
|
|
|
func RegisterTypeEncoderFunc(typ string, fun EncoderFunc, isEmptyFunc func(unsafe.Pointer) bool) {
|
|
|
|
typeEncoders[typ] = &funcEncoder{fun, isEmptyFunc}
|
|
|
|
}
|
|
|
|
|
|
|
|
// RegisterTypeEncoder register TypeEncoder for a type
|
|
|
|
func RegisterTypeEncoder(typ string, encoder ValEncoder) {
|
|
|
|
typeEncoders[typ] = encoder
|
|
|
|
}
|
|
|
|
|
|
|
|
// RegisterFieldEncoderFunc register TypeEncoder for a struct field with encode/isEmpty function
|
|
|
|
func RegisterFieldEncoderFunc(typ string, field string, fun EncoderFunc, isEmptyFunc func(unsafe.Pointer) bool) {
|
|
|
|
RegisterFieldEncoder(typ, field, &funcEncoder{fun, isEmptyFunc})
|
|
|
|
}
|
|
|
|
|
|
|
|
// RegisterFieldEncoder register TypeEncoder for a struct field
|
|
|
|
func RegisterFieldEncoder(typ string, field string, encoder ValEncoder) {
|
|
|
|
fieldEncoders[fmt.Sprintf("%s/%s", typ, field)] = encoder
|
|
|
|
}
|
|
|
|
|
|
|
|
// RegisterExtension register extension
|
|
|
|
func RegisterExtension(extension Extension) {
|
|
|
|
extensions = append(extensions, extension)
|
|
|
|
}
|
|
|
|
|
2018-07-25 04:17:02 -04:00
|
|
|
func getTypeDecoderFromExtension(ctx *ctx, typ reflect2.Type) ValDecoder {
|
|
|
|
decoder := _getTypeDecoderFromExtension(ctx, typ)
|
2017-11-20 09:30:52 -05:00
|
|
|
if decoder != nil {
|
|
|
|
for _, extension := range extensions {
|
|
|
|
decoder = extension.DecorateDecoder(typ, decoder)
|
|
|
|
}
|
2018-09-26 07:26:19 -04:00
|
|
|
decoder = ctx.decoderExtension.DecorateDecoder(typ, decoder)
|
|
|
|
for _, extension := range ctx.extraExtensions {
|
2018-07-25 04:17:02 -04:00
|
|
|
decoder = extension.DecorateDecoder(typ, decoder)
|
|
|
|
}
|
2017-11-20 09:30:52 -05:00
|
|
|
}
|
|
|
|
return decoder
|
|
|
|
}
|
2018-07-25 04:17:02 -04:00
|
|
|
func _getTypeDecoderFromExtension(ctx *ctx, typ reflect2.Type) ValDecoder {
|
2017-11-20 09:30:52 -05:00
|
|
|
for _, extension := range extensions {
|
|
|
|
decoder := extension.CreateDecoder(typ)
|
|
|
|
if decoder != nil {
|
|
|
|
return decoder
|
|
|
|
}
|
|
|
|
}
|
2018-09-26 07:26:19 -04:00
|
|
|
decoder := ctx.decoderExtension.CreateDecoder(typ)
|
|
|
|
if decoder != nil {
|
|
|
|
return decoder
|
|
|
|
}
|
|
|
|
for _, extension := range ctx.extraExtensions {
|
2018-07-25 04:17:02 -04:00
|
|
|
decoder := extension.CreateDecoder(typ)
|
|
|
|
if decoder != nil {
|
|
|
|
return decoder
|
|
|
|
}
|
|
|
|
}
|
2017-11-20 09:30:52 -05:00
|
|
|
typeName := typ.String()
|
2018-09-26 07:26:19 -04:00
|
|
|
decoder = typeDecoders[typeName]
|
2017-11-20 09:30:52 -05:00
|
|
|
if decoder != nil {
|
|
|
|
return decoder
|
|
|
|
}
|
|
|
|
if typ.Kind() == reflect.Ptr {
|
2018-07-25 04:17:02 -04:00
|
|
|
ptrType := typ.(*reflect2.UnsafePtrType)
|
|
|
|
decoder := typeDecoders[ptrType.Elem().String()]
|
2017-11-20 09:30:52 -05:00
|
|
|
if decoder != nil {
|
2018-07-25 04:17:02 -04:00
|
|
|
return &OptionalDecoder{ptrType.Elem(), decoder}
|
2017-11-20 09:30:52 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-07-25 04:17:02 -04:00
|
|
|
func getTypeEncoderFromExtension(ctx *ctx, typ reflect2.Type) ValEncoder {
|
|
|
|
encoder := _getTypeEncoderFromExtension(ctx, typ)
|
2017-11-20 09:30:52 -05:00
|
|
|
if encoder != nil {
|
|
|
|
for _, extension := range extensions {
|
|
|
|
encoder = extension.DecorateEncoder(typ, encoder)
|
|
|
|
}
|
2018-09-26 07:26:19 -04:00
|
|
|
encoder = ctx.encoderExtension.DecorateEncoder(typ, encoder)
|
|
|
|
for _, extension := range ctx.extraExtensions {
|
2018-07-25 04:17:02 -04:00
|
|
|
encoder = extension.DecorateEncoder(typ, encoder)
|
|
|
|
}
|
2017-11-20 09:30:52 -05:00
|
|
|
}
|
|
|
|
return encoder
|
|
|
|
}
|
|
|
|
|
2018-07-25 04:17:02 -04:00
|
|
|
func _getTypeEncoderFromExtension(ctx *ctx, typ reflect2.Type) ValEncoder {
|
2017-11-20 09:30:52 -05:00
|
|
|
for _, extension := range extensions {
|
|
|
|
encoder := extension.CreateEncoder(typ)
|
|
|
|
if encoder != nil {
|
|
|
|
return encoder
|
|
|
|
}
|
|
|
|
}
|
2018-09-26 07:26:19 -04:00
|
|
|
encoder := ctx.encoderExtension.CreateEncoder(typ)
|
|
|
|
if encoder != nil {
|
|
|
|
return encoder
|
|
|
|
}
|
|
|
|
for _, extension := range ctx.extraExtensions {
|
2018-07-25 04:17:02 -04:00
|
|
|
encoder := extension.CreateEncoder(typ)
|
|
|
|
if encoder != nil {
|
|
|
|
return encoder
|
|
|
|
}
|
|
|
|
}
|
2017-11-20 09:30:52 -05:00
|
|
|
typeName := typ.String()
|
2018-09-26 07:26:19 -04:00
|
|
|
encoder = typeEncoders[typeName]
|
2017-11-20 09:30:52 -05:00
|
|
|
if encoder != nil {
|
|
|
|
return encoder
|
|
|
|
}
|
|
|
|
if typ.Kind() == reflect.Ptr {
|
2018-07-25 04:17:02 -04:00
|
|
|
typePtr := typ.(*reflect2.UnsafePtrType)
|
|
|
|
encoder := typeEncoders[typePtr.Elem().String()]
|
2017-11-20 09:30:52 -05:00
|
|
|
if encoder != nil {
|
2018-07-25 04:17:02 -04:00
|
|
|
return &OptionalEncoder{encoder}
|
2017-11-20 09:30:52 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-07-25 04:17:02 -04:00
|
|
|
func describeStruct(ctx *ctx, typ reflect2.Type) *StructDescriptor {
|
|
|
|
structType := typ.(*reflect2.UnsafeStructType)
|
2017-11-20 09:30:52 -05:00
|
|
|
embeddedBindings := []*Binding{}
|
|
|
|
bindings := []*Binding{}
|
2018-07-25 04:17:02 -04:00
|
|
|
for i := 0; i < structType.NumField(); i++ {
|
|
|
|
field := structType.Field(i)
|
|
|
|
tag, hastag := field.Tag().Lookup(ctx.getTagKey())
|
2019-03-19 11:30:11 -04:00
|
|
|
if ctx.onlyTaggedField && !hastag && !field.Anonymous() {
|
2018-07-25 04:17:02 -04:00
|
|
|
continue
|
|
|
|
}
|
[20.10] vendor: github.com/json-iterator/go v1.1.12 for Go 1.18 compatibility
full diff: https://github.com/json-iterator/go/compare/0ff49de124c6f76f8494e194af75bde0f1a49a29...024077e996b048517130b21ea6bf12aa23055d3d
Fixes a nil-pointer exception on go 1.18;
```
=== FAIL: cli/context/kubernetes TestSaveLoadContexts (0.00s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x40fcbc]
goroutine 19 [running]:
testing.tRunner.func1.2({0xa7e080, 0x1073930})
/usr/local/go/src/testing/testing.go:1389 +0x24e
testing.tRunner.func1()
/usr/local/go/src/testing/testing.go:1392 +0x39f
panic({0xa7e080, 0x1073930})
/usr/local/go/src/runtime/panic.go:838 +0x207
reflect.mapiternext(0x40?)
/usr/local/go/src/runtime/map.go:1378 +0x19
github.com/docker/cli/vendor/github.com/modern-go/reflect2.(*UnsafeMapIterator).UnsafeNext(0x8?)
/go/src/github.com/docker/cli/vendor/github.com/modern-go/reflect2/unsafe_map.go:136 +0x32
github.com/docker/cli/vendor/github.com/json-iterator/go.(*sortKeysMapEncoder).Encode(0xc000478930, 0xc0000ca3a8, 0xc0000bae40)
/go/src/github.com/docker/cli/vendor/github.com/json-iterator/go/reflect_map.go:293 +0x335
github.com/docker/cli/vendor/github.com/json-iterator/go.(*placeholderEncoder).Encode(0xc00046c898?, 0x95d787?, 0xc0000bae58?)
/go/src/github.com/docker/cli/vendor/github.com/json-iterator/go/reflect.go:327 +0x22
github.com/docker/cli/vendor/github.com/json-iterator/go.(*structFieldEncoder).Encode(0xc000482630, 0xa2790c?, 0xc0000bae40)
/go/src/github.com/docker/cli/vendor/github.com/json-iterator/go/reflect_struct_encoder.go:110 +0x56
github.com/docker/cli/vendor/github.com/json-iterator/go.(*structEncoder).Encode(0xc000482780, 0xb3a599?, 0xc0000bae40)
/go/src/github.com/docker/cli/vendor/github.com/json-iterator/go/reflect_struct_encoder.go:158 +0x652
github.com/docker/cli/vendor/github.com/json-iterator/go.(*placeholderEncoder).Encode(0xc00046ca10?, 0x95d787?, 0xc0000bae58?)
/go/src/github.com/docker/cli/vendor/github.com/json-iterator/go/reflect.go:327 +0x22
github.com/docker/cli/vendor/github.com/json-iterator/go.(*structFieldEncoder).Encode(0xc0004829f0, 0xa0fd11?, 0xc0000bae40)
/go/src/github.com/docker/cli/vendor/github.com/json-iterator/go/reflect_struct_encoder.go:110 +0x56
github.com/docker/cli/vendor/github.com/json-iterator/go.(*structEncoder).Encode(0xc000482a50, 0x40aa15?, 0xc0000bae40)
/go/src/github.com/docker/cli/vendor/github.com/json-iterator/go/reflect_struct_encoder.go:158 +0x652
github.com/docker/cli/vendor/github.com/json-iterator/go.(*sliceEncoder).Encode(0xc00047e198, 0xc0003a83c8, 0xc0000bae40)
/go/src/github.com/docker/cli/vendor/github.com/json-iterator/go/reflect_slice.go:38 +0x2bb
github.com/docker/cli/vendor/github.com/json-iterator/go.(*structFieldEncoder).Encode(0xc0004837a0, 0xa12e12?, 0xc0000bae40)
/go/src/github.com/docker/cli/vendor/github.com/json-iterator/go/reflect_struct_encoder.go:110 +0x56
github.com/docker/cli/vendor/github.com/json-iterator/go.(*structEncoder).Encode(0xc000483890, 0x0?, 0xc0000bae40)
/go/src/github.com/docker/cli/vendor/github.com/json-iterator/go/reflect_struct_encoder.go:158 +0x652
github.com/docker/cli/vendor/github.com/json-iterator/go.(*OptionalEncoder).Encode(0xc0003b6be0?, 0x0?, 0x0?)
/go/src/github.com/docker/cli/vendor/github.com/json-iterator/go/reflect_optional.go:74 +0xa4
github.com/docker/cli/vendor/github.com/json-iterator/go.(*onePtrEncoder).Encode(0xc000471e30, 0xc0003a8370, 0xc000460720?)
/go/src/github.com/docker/cli/vendor/github.com/json-iterator/go/reflect.go:214 +0x82
github.com/docker/cli/vendor/github.com/json-iterator/go.(*Stream).WriteVal(0xc0000bae40, {0xabe4a0, 0xc0003a8370})
/go/src/github.com/docker/cli/vendor/github.com/json-iterator/go/reflect.go:93 +0x158
github.com/docker/cli/vendor/github.com/json-iterator/go.(*frozenConfig).Marshal(0xc0003b6be0, {0xabe4a0, 0xc0003a8370})
/go/src/github.com/docker/cli/vendor/github.com/json-iterator/go/config.go:299 +0xc9
github.com/docker/cli/vendor/k8s.io/apimachinery/pkg/runtime/serializer/json.(*Serializer).Encode(0xc00043aee0?, {0xc375c0?, 0xc0003a8370?}, {0xc339e0, 0xc000460210})
/go/src/github.com/docker/cli/vendor/k8s.io/apimachinery/pkg/runtime/serializer/json/json.go:310 +0x6d
github.com/docker/cli/vendor/k8s.io/apimachinery/pkg/runtime/serializer/versioning.(*codec).Encode(0xc0000f8480, {0xc37570?, 0xc0000bacc0}, {0xc339e0, 0xc000460210})
/go/src/github.com/docker/cli/vendor/k8s.io/apimachinery/pkg/runtime/serializer/versioning/versioning.go:231 +0x926
github.com/docker/cli/vendor/k8s.io/apimachinery/pkg/runtime.Encode({0x7f48b36ce5c0, 0xc0000f8480}, {0xc37570, 0xc0000bacc0})
/go/src/github.com/docker/cli/vendor/k8s.io/apimachinery/pkg/runtime/codec.go:46 +0x64
github.com/docker/cli/vendor/k8s.io/client-go/tools/clientcmd.Write(...)
/go/src/github.com/docker/cli/vendor/k8s.io/client-go/tools/clientcmd/loader.go:469
github.com/docker/cli/cli/context/kubernetes.TestSaveLoadContexts(0xc0004561a0?)
/go/src/github.com/docker/cli/cli/context/kubernetes/endpoint_test.go:75 +0xf0a
testing.tRunner(0xc0004561a0, 0xb89ea0)
/usr/local/go/src/testing/testing.go:1439 +0x102
created by testing.(*T).Run
/usr/local/go/src/testing/testing.go:1486 +0x35f
```
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-08-19 10:12:25 -04:00
|
|
|
if tag == "-" || field.Name() == "_" {
|
2017-11-20 09:30:52 -05:00
|
|
|
continue
|
|
|
|
}
|
[20.10] vendor: github.com/json-iterator/go v1.1.12 for Go 1.18 compatibility
full diff: https://github.com/json-iterator/go/compare/0ff49de124c6f76f8494e194af75bde0f1a49a29...024077e996b048517130b21ea6bf12aa23055d3d
Fixes a nil-pointer exception on go 1.18;
```
=== FAIL: cli/context/kubernetes TestSaveLoadContexts (0.00s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x40fcbc]
goroutine 19 [running]:
testing.tRunner.func1.2({0xa7e080, 0x1073930})
/usr/local/go/src/testing/testing.go:1389 +0x24e
testing.tRunner.func1()
/usr/local/go/src/testing/testing.go:1392 +0x39f
panic({0xa7e080, 0x1073930})
/usr/local/go/src/runtime/panic.go:838 +0x207
reflect.mapiternext(0x40?)
/usr/local/go/src/runtime/map.go:1378 +0x19
github.com/docker/cli/vendor/github.com/modern-go/reflect2.(*UnsafeMapIterator).UnsafeNext(0x8?)
/go/src/github.com/docker/cli/vendor/github.com/modern-go/reflect2/unsafe_map.go:136 +0x32
github.com/docker/cli/vendor/github.com/json-iterator/go.(*sortKeysMapEncoder).Encode(0xc000478930, 0xc0000ca3a8, 0xc0000bae40)
/go/src/github.com/docker/cli/vendor/github.com/json-iterator/go/reflect_map.go:293 +0x335
github.com/docker/cli/vendor/github.com/json-iterator/go.(*placeholderEncoder).Encode(0xc00046c898?, 0x95d787?, 0xc0000bae58?)
/go/src/github.com/docker/cli/vendor/github.com/json-iterator/go/reflect.go:327 +0x22
github.com/docker/cli/vendor/github.com/json-iterator/go.(*structFieldEncoder).Encode(0xc000482630, 0xa2790c?, 0xc0000bae40)
/go/src/github.com/docker/cli/vendor/github.com/json-iterator/go/reflect_struct_encoder.go:110 +0x56
github.com/docker/cli/vendor/github.com/json-iterator/go.(*structEncoder).Encode(0xc000482780, 0xb3a599?, 0xc0000bae40)
/go/src/github.com/docker/cli/vendor/github.com/json-iterator/go/reflect_struct_encoder.go:158 +0x652
github.com/docker/cli/vendor/github.com/json-iterator/go.(*placeholderEncoder).Encode(0xc00046ca10?, 0x95d787?, 0xc0000bae58?)
/go/src/github.com/docker/cli/vendor/github.com/json-iterator/go/reflect.go:327 +0x22
github.com/docker/cli/vendor/github.com/json-iterator/go.(*structFieldEncoder).Encode(0xc0004829f0, 0xa0fd11?, 0xc0000bae40)
/go/src/github.com/docker/cli/vendor/github.com/json-iterator/go/reflect_struct_encoder.go:110 +0x56
github.com/docker/cli/vendor/github.com/json-iterator/go.(*structEncoder).Encode(0xc000482a50, 0x40aa15?, 0xc0000bae40)
/go/src/github.com/docker/cli/vendor/github.com/json-iterator/go/reflect_struct_encoder.go:158 +0x652
github.com/docker/cli/vendor/github.com/json-iterator/go.(*sliceEncoder).Encode(0xc00047e198, 0xc0003a83c8, 0xc0000bae40)
/go/src/github.com/docker/cli/vendor/github.com/json-iterator/go/reflect_slice.go:38 +0x2bb
github.com/docker/cli/vendor/github.com/json-iterator/go.(*structFieldEncoder).Encode(0xc0004837a0, 0xa12e12?, 0xc0000bae40)
/go/src/github.com/docker/cli/vendor/github.com/json-iterator/go/reflect_struct_encoder.go:110 +0x56
github.com/docker/cli/vendor/github.com/json-iterator/go.(*structEncoder).Encode(0xc000483890, 0x0?, 0xc0000bae40)
/go/src/github.com/docker/cli/vendor/github.com/json-iterator/go/reflect_struct_encoder.go:158 +0x652
github.com/docker/cli/vendor/github.com/json-iterator/go.(*OptionalEncoder).Encode(0xc0003b6be0?, 0x0?, 0x0?)
/go/src/github.com/docker/cli/vendor/github.com/json-iterator/go/reflect_optional.go:74 +0xa4
github.com/docker/cli/vendor/github.com/json-iterator/go.(*onePtrEncoder).Encode(0xc000471e30, 0xc0003a8370, 0xc000460720?)
/go/src/github.com/docker/cli/vendor/github.com/json-iterator/go/reflect.go:214 +0x82
github.com/docker/cli/vendor/github.com/json-iterator/go.(*Stream).WriteVal(0xc0000bae40, {0xabe4a0, 0xc0003a8370})
/go/src/github.com/docker/cli/vendor/github.com/json-iterator/go/reflect.go:93 +0x158
github.com/docker/cli/vendor/github.com/json-iterator/go.(*frozenConfig).Marshal(0xc0003b6be0, {0xabe4a0, 0xc0003a8370})
/go/src/github.com/docker/cli/vendor/github.com/json-iterator/go/config.go:299 +0xc9
github.com/docker/cli/vendor/k8s.io/apimachinery/pkg/runtime/serializer/json.(*Serializer).Encode(0xc00043aee0?, {0xc375c0?, 0xc0003a8370?}, {0xc339e0, 0xc000460210})
/go/src/github.com/docker/cli/vendor/k8s.io/apimachinery/pkg/runtime/serializer/json/json.go:310 +0x6d
github.com/docker/cli/vendor/k8s.io/apimachinery/pkg/runtime/serializer/versioning.(*codec).Encode(0xc0000f8480, {0xc37570?, 0xc0000bacc0}, {0xc339e0, 0xc000460210})
/go/src/github.com/docker/cli/vendor/k8s.io/apimachinery/pkg/runtime/serializer/versioning/versioning.go:231 +0x926
github.com/docker/cli/vendor/k8s.io/apimachinery/pkg/runtime.Encode({0x7f48b36ce5c0, 0xc0000f8480}, {0xc37570, 0xc0000bacc0})
/go/src/github.com/docker/cli/vendor/k8s.io/apimachinery/pkg/runtime/codec.go:46 +0x64
github.com/docker/cli/vendor/k8s.io/client-go/tools/clientcmd.Write(...)
/go/src/github.com/docker/cli/vendor/k8s.io/client-go/tools/clientcmd/loader.go:469
github.com/docker/cli/cli/context/kubernetes.TestSaveLoadContexts(0xc0004561a0?)
/go/src/github.com/docker/cli/cli/context/kubernetes/endpoint_test.go:75 +0xf0a
testing.tRunner(0xc0004561a0, 0xb89ea0)
/usr/local/go/src/testing/testing.go:1439 +0x102
created by testing.(*T).Run
/usr/local/go/src/testing/testing.go:1486 +0x35f
```
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-08-19 10:12:25 -04:00
|
|
|
tagParts := strings.Split(tag, ",")
|
2018-07-25 04:17:02 -04:00
|
|
|
if field.Anonymous() && (tag == "" || tagParts[0] == "") {
|
|
|
|
if field.Type().Kind() == reflect.Struct {
|
|
|
|
structDescriptor := describeStruct(ctx, field.Type())
|
2017-11-20 09:30:52 -05:00
|
|
|
for _, binding := range structDescriptor.Fields {
|
|
|
|
binding.levels = append([]int{i}, binding.levels...)
|
|
|
|
omitempty := binding.Encoder.(*structFieldEncoder).omitempty
|
2018-07-25 04:17:02 -04:00
|
|
|
binding.Encoder = &structFieldEncoder{field, binding.Encoder, omitempty}
|
|
|
|
binding.Decoder = &structFieldDecoder{field, binding.Decoder}
|
2017-11-20 09:30:52 -05:00
|
|
|
embeddedBindings = append(embeddedBindings, binding)
|
|
|
|
}
|
|
|
|
continue
|
2018-07-25 04:17:02 -04:00
|
|
|
} else if field.Type().Kind() == reflect.Ptr {
|
|
|
|
ptrType := field.Type().(*reflect2.UnsafePtrType)
|
|
|
|
if ptrType.Elem().Kind() == reflect.Struct {
|
|
|
|
structDescriptor := describeStruct(ctx, ptrType.Elem())
|
|
|
|
for _, binding := range structDescriptor.Fields {
|
|
|
|
binding.levels = append([]int{i}, binding.levels...)
|
|
|
|
omitempty := binding.Encoder.(*structFieldEncoder).omitempty
|
|
|
|
binding.Encoder = &dereferenceEncoder{binding.Encoder}
|
|
|
|
binding.Encoder = &structFieldEncoder{field, binding.Encoder, omitempty}
|
|
|
|
binding.Decoder = &dereferenceDecoder{ptrType.Elem(), binding.Decoder}
|
|
|
|
binding.Decoder = &structFieldDecoder{field, binding.Decoder}
|
|
|
|
embeddedBindings = append(embeddedBindings, binding)
|
|
|
|
}
|
|
|
|
continue
|
2017-11-20 09:30:52 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-07-25 04:17:02 -04:00
|
|
|
fieldNames := calcFieldNames(field.Name(), tagParts[0], tag)
|
|
|
|
fieldCacheKey := fmt.Sprintf("%s/%s", typ.String(), field.Name())
|
2017-11-20 09:30:52 -05:00
|
|
|
decoder := fieldDecoders[fieldCacheKey]
|
|
|
|
if decoder == nil {
|
2018-07-25 04:17:02 -04:00
|
|
|
decoder = decoderOfType(ctx.append(field.Name()), field.Type())
|
2017-11-20 09:30:52 -05:00
|
|
|
}
|
|
|
|
encoder := fieldEncoders[fieldCacheKey]
|
|
|
|
if encoder == nil {
|
2018-07-25 04:17:02 -04:00
|
|
|
encoder = encoderOfType(ctx.append(field.Name()), field.Type())
|
2017-11-20 09:30:52 -05:00
|
|
|
}
|
|
|
|
binding := &Binding{
|
2018-07-25 04:17:02 -04:00
|
|
|
Field: field,
|
2017-11-20 09:30:52 -05:00
|
|
|
FromNames: fieldNames,
|
|
|
|
ToNames: fieldNames,
|
|
|
|
Decoder: decoder,
|
|
|
|
Encoder: encoder,
|
|
|
|
}
|
|
|
|
binding.levels = []int{i}
|
|
|
|
bindings = append(bindings, binding)
|
|
|
|
}
|
2018-07-25 04:17:02 -04:00
|
|
|
return createStructDescriptor(ctx, typ, bindings, embeddedBindings)
|
|
|
|
}
|
|
|
|
func createStructDescriptor(ctx *ctx, typ reflect2.Type, bindings []*Binding, embeddedBindings []*Binding) *StructDescriptor {
|
2017-11-20 09:30:52 -05:00
|
|
|
structDescriptor := &StructDescriptor{
|
2018-07-25 04:17:02 -04:00
|
|
|
Type: typ,
|
|
|
|
Fields: bindings,
|
2017-11-20 09:30:52 -05:00
|
|
|
}
|
|
|
|
for _, extension := range extensions {
|
|
|
|
extension.UpdateStructDescriptor(structDescriptor)
|
|
|
|
}
|
2018-09-26 07:26:19 -04:00
|
|
|
ctx.encoderExtension.UpdateStructDescriptor(structDescriptor)
|
|
|
|
ctx.decoderExtension.UpdateStructDescriptor(structDescriptor)
|
|
|
|
for _, extension := range ctx.extraExtensions {
|
2018-07-25 04:17:02 -04:00
|
|
|
extension.UpdateStructDescriptor(structDescriptor)
|
|
|
|
}
|
|
|
|
processTags(structDescriptor, ctx.frozenConfig)
|
2017-11-20 09:30:52 -05:00
|
|
|
// merge normal & embedded bindings & sort with original order
|
|
|
|
allBindings := sortableBindings(append(embeddedBindings, structDescriptor.Fields...))
|
|
|
|
sort.Sort(allBindings)
|
|
|
|
structDescriptor.Fields = allBindings
|
|
|
|
return structDescriptor
|
|
|
|
}
|
|
|
|
|
|
|
|
type sortableBindings []*Binding
|
|
|
|
|
|
|
|
func (bindings sortableBindings) Len() int {
|
|
|
|
return len(bindings)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (bindings sortableBindings) Less(i, j int) bool {
|
|
|
|
left := bindings[i].levels
|
|
|
|
right := bindings[j].levels
|
|
|
|
k := 0
|
|
|
|
for {
|
|
|
|
if left[k] < right[k] {
|
|
|
|
return true
|
|
|
|
} else if left[k] > right[k] {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
k++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (bindings sortableBindings) Swap(i, j int) {
|
|
|
|
bindings[i], bindings[j] = bindings[j], bindings[i]
|
|
|
|
}
|
|
|
|
|
|
|
|
func processTags(structDescriptor *StructDescriptor, cfg *frozenConfig) {
|
|
|
|
for _, binding := range structDescriptor.Fields {
|
|
|
|
shouldOmitEmpty := false
|
2018-07-25 04:17:02 -04:00
|
|
|
tagParts := strings.Split(binding.Field.Tag().Get(cfg.getTagKey()), ",")
|
2017-11-20 09:30:52 -05:00
|
|
|
for _, tagPart := range tagParts[1:] {
|
|
|
|
if tagPart == "omitempty" {
|
|
|
|
shouldOmitEmpty = true
|
|
|
|
} else if tagPart == "string" {
|
2018-07-25 04:17:02 -04:00
|
|
|
if binding.Field.Type().Kind() == reflect.String {
|
2017-11-20 09:30:52 -05:00
|
|
|
binding.Decoder = &stringModeStringDecoder{binding.Decoder, cfg}
|
|
|
|
binding.Encoder = &stringModeStringEncoder{binding.Encoder, cfg}
|
|
|
|
} else {
|
|
|
|
binding.Decoder = &stringModeNumberDecoder{binding.Decoder}
|
|
|
|
binding.Encoder = &stringModeNumberEncoder{binding.Encoder}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
binding.Decoder = &structFieldDecoder{binding.Field, binding.Decoder}
|
|
|
|
binding.Encoder = &structFieldEncoder{binding.Field, binding.Encoder, shouldOmitEmpty}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func calcFieldNames(originalFieldName string, tagProvidedFieldName string, wholeTag string) []string {
|
|
|
|
// ignore?
|
|
|
|
if wholeTag == "-" {
|
|
|
|
return []string{}
|
|
|
|
}
|
|
|
|
// rename?
|
|
|
|
var fieldNames []string
|
|
|
|
if tagProvidedFieldName == "" {
|
|
|
|
fieldNames = []string{originalFieldName}
|
|
|
|
} else {
|
|
|
|
fieldNames = []string{tagProvidedFieldName}
|
|
|
|
}
|
|
|
|
// private?
|
[20.10] vendor: github.com/json-iterator/go v1.1.12 for Go 1.18 compatibility
full diff: https://github.com/json-iterator/go/compare/0ff49de124c6f76f8494e194af75bde0f1a49a29...024077e996b048517130b21ea6bf12aa23055d3d
Fixes a nil-pointer exception on go 1.18;
```
=== FAIL: cli/context/kubernetes TestSaveLoadContexts (0.00s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x40fcbc]
goroutine 19 [running]:
testing.tRunner.func1.2({0xa7e080, 0x1073930})
/usr/local/go/src/testing/testing.go:1389 +0x24e
testing.tRunner.func1()
/usr/local/go/src/testing/testing.go:1392 +0x39f
panic({0xa7e080, 0x1073930})
/usr/local/go/src/runtime/panic.go:838 +0x207
reflect.mapiternext(0x40?)
/usr/local/go/src/runtime/map.go:1378 +0x19
github.com/docker/cli/vendor/github.com/modern-go/reflect2.(*UnsafeMapIterator).UnsafeNext(0x8?)
/go/src/github.com/docker/cli/vendor/github.com/modern-go/reflect2/unsafe_map.go:136 +0x32
github.com/docker/cli/vendor/github.com/json-iterator/go.(*sortKeysMapEncoder).Encode(0xc000478930, 0xc0000ca3a8, 0xc0000bae40)
/go/src/github.com/docker/cli/vendor/github.com/json-iterator/go/reflect_map.go:293 +0x335
github.com/docker/cli/vendor/github.com/json-iterator/go.(*placeholderEncoder).Encode(0xc00046c898?, 0x95d787?, 0xc0000bae58?)
/go/src/github.com/docker/cli/vendor/github.com/json-iterator/go/reflect.go:327 +0x22
github.com/docker/cli/vendor/github.com/json-iterator/go.(*structFieldEncoder).Encode(0xc000482630, 0xa2790c?, 0xc0000bae40)
/go/src/github.com/docker/cli/vendor/github.com/json-iterator/go/reflect_struct_encoder.go:110 +0x56
github.com/docker/cli/vendor/github.com/json-iterator/go.(*structEncoder).Encode(0xc000482780, 0xb3a599?, 0xc0000bae40)
/go/src/github.com/docker/cli/vendor/github.com/json-iterator/go/reflect_struct_encoder.go:158 +0x652
github.com/docker/cli/vendor/github.com/json-iterator/go.(*placeholderEncoder).Encode(0xc00046ca10?, 0x95d787?, 0xc0000bae58?)
/go/src/github.com/docker/cli/vendor/github.com/json-iterator/go/reflect.go:327 +0x22
github.com/docker/cli/vendor/github.com/json-iterator/go.(*structFieldEncoder).Encode(0xc0004829f0, 0xa0fd11?, 0xc0000bae40)
/go/src/github.com/docker/cli/vendor/github.com/json-iterator/go/reflect_struct_encoder.go:110 +0x56
github.com/docker/cli/vendor/github.com/json-iterator/go.(*structEncoder).Encode(0xc000482a50, 0x40aa15?, 0xc0000bae40)
/go/src/github.com/docker/cli/vendor/github.com/json-iterator/go/reflect_struct_encoder.go:158 +0x652
github.com/docker/cli/vendor/github.com/json-iterator/go.(*sliceEncoder).Encode(0xc00047e198, 0xc0003a83c8, 0xc0000bae40)
/go/src/github.com/docker/cli/vendor/github.com/json-iterator/go/reflect_slice.go:38 +0x2bb
github.com/docker/cli/vendor/github.com/json-iterator/go.(*structFieldEncoder).Encode(0xc0004837a0, 0xa12e12?, 0xc0000bae40)
/go/src/github.com/docker/cli/vendor/github.com/json-iterator/go/reflect_struct_encoder.go:110 +0x56
github.com/docker/cli/vendor/github.com/json-iterator/go.(*structEncoder).Encode(0xc000483890, 0x0?, 0xc0000bae40)
/go/src/github.com/docker/cli/vendor/github.com/json-iterator/go/reflect_struct_encoder.go:158 +0x652
github.com/docker/cli/vendor/github.com/json-iterator/go.(*OptionalEncoder).Encode(0xc0003b6be0?, 0x0?, 0x0?)
/go/src/github.com/docker/cli/vendor/github.com/json-iterator/go/reflect_optional.go:74 +0xa4
github.com/docker/cli/vendor/github.com/json-iterator/go.(*onePtrEncoder).Encode(0xc000471e30, 0xc0003a8370, 0xc000460720?)
/go/src/github.com/docker/cli/vendor/github.com/json-iterator/go/reflect.go:214 +0x82
github.com/docker/cli/vendor/github.com/json-iterator/go.(*Stream).WriteVal(0xc0000bae40, {0xabe4a0, 0xc0003a8370})
/go/src/github.com/docker/cli/vendor/github.com/json-iterator/go/reflect.go:93 +0x158
github.com/docker/cli/vendor/github.com/json-iterator/go.(*frozenConfig).Marshal(0xc0003b6be0, {0xabe4a0, 0xc0003a8370})
/go/src/github.com/docker/cli/vendor/github.com/json-iterator/go/config.go:299 +0xc9
github.com/docker/cli/vendor/k8s.io/apimachinery/pkg/runtime/serializer/json.(*Serializer).Encode(0xc00043aee0?, {0xc375c0?, 0xc0003a8370?}, {0xc339e0, 0xc000460210})
/go/src/github.com/docker/cli/vendor/k8s.io/apimachinery/pkg/runtime/serializer/json/json.go:310 +0x6d
github.com/docker/cli/vendor/k8s.io/apimachinery/pkg/runtime/serializer/versioning.(*codec).Encode(0xc0000f8480, {0xc37570?, 0xc0000bacc0}, {0xc339e0, 0xc000460210})
/go/src/github.com/docker/cli/vendor/k8s.io/apimachinery/pkg/runtime/serializer/versioning/versioning.go:231 +0x926
github.com/docker/cli/vendor/k8s.io/apimachinery/pkg/runtime.Encode({0x7f48b36ce5c0, 0xc0000f8480}, {0xc37570, 0xc0000bacc0})
/go/src/github.com/docker/cli/vendor/k8s.io/apimachinery/pkg/runtime/codec.go:46 +0x64
github.com/docker/cli/vendor/k8s.io/client-go/tools/clientcmd.Write(...)
/go/src/github.com/docker/cli/vendor/k8s.io/client-go/tools/clientcmd/loader.go:469
github.com/docker/cli/cli/context/kubernetes.TestSaveLoadContexts(0xc0004561a0?)
/go/src/github.com/docker/cli/cli/context/kubernetes/endpoint_test.go:75 +0xf0a
testing.tRunner(0xc0004561a0, 0xb89ea0)
/usr/local/go/src/testing/testing.go:1439 +0x102
created by testing.(*T).Run
/usr/local/go/src/testing/testing.go:1486 +0x35f
```
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-08-19 10:12:25 -04:00
|
|
|
isNotExported := unicode.IsLower(rune(originalFieldName[0])) || originalFieldName[0] == '_'
|
2017-11-20 09:30:52 -05:00
|
|
|
if isNotExported {
|
|
|
|
fieldNames = []string{}
|
|
|
|
}
|
|
|
|
return fieldNames
|
|
|
|
}
|