mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-11 21:12:07 +00:00
Add WithSerializer option to add serializers to CodecFactory.
This commit is contained in:
parent
66a14268c5
commit
db1239d354
@ -89,6 +89,10 @@ func newSerializersForScheme(scheme *runtime.Scheme, mf json.MetaFactory, option
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, f := range options.serializers {
|
||||||
|
serializers = append(serializers, f(scheme, scheme))
|
||||||
|
}
|
||||||
|
|
||||||
return serializers
|
return serializers
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,6 +112,8 @@ type CodecFactoryOptions struct {
|
|||||||
Strict bool
|
Strict bool
|
||||||
// Pretty includes a pretty serializer along with the non-pretty one
|
// Pretty includes a pretty serializer along with the non-pretty one
|
||||||
Pretty bool
|
Pretty bool
|
||||||
|
|
||||||
|
serializers []func(runtime.ObjectCreater, runtime.ObjectTyper) runtime.SerializerInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
// CodecFactoryOptionsMutator takes a pointer to an options struct and then modifies it.
|
// CodecFactoryOptionsMutator takes a pointer to an options struct and then modifies it.
|
||||||
@ -134,6 +140,13 @@ func DisableStrict(options *CodecFactoryOptions) {
|
|||||||
options.Strict = false
|
options.Strict = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithSerializer configures a serializer to be supported in addition to the default serializers.
|
||||||
|
func WithSerializer(f func(runtime.ObjectCreater, runtime.ObjectTyper) runtime.SerializerInfo) CodecFactoryOptionsMutator {
|
||||||
|
return func(options *CodecFactoryOptions) {
|
||||||
|
options.serializers = append(options.serializers, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// NewCodecFactory provides methods for retrieving serializers for the supported wire formats
|
// NewCodecFactory provides methods for retrieving serializers for the supported wire formats
|
||||||
// and conversion wrappers to define preferred internal and external versions. In the future,
|
// and conversion wrappers to define preferred internal and external versions. In the future,
|
||||||
// as the internal version is used less, callers may instead use a defaulting serializer and
|
// as the internal version is used less, callers may instead use a defaulting serializer and
|
||||||
|
Loading…
Reference in New Issue
Block a user