From efc0f2987f852fb2ec6d62a38a64c1e131aec569 Mon Sep 17 00:00:00 2001 From: Tom Denham Date: Tue, 31 May 2016 17:12:40 -0700 Subject: [PATCH] pkg/types: Add UnmarshallableString type Allow strings to be unmarshalled for CNI_ARGS CNI_ARGS uses types.LoadArgs to populate a struct. The fields in the struct must meet the TextUnmarshaler interface. This code adds a UnmarshallableString type to assist with this. --- types/args.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/types/args.go b/types/args.go index 3b667b0f..66dcf9ea 100644 --- a/types/args.go +++ b/types/args.go @@ -41,6 +41,16 @@ func (b *UnmarshallableBool) UnmarshalText(data []byte) error { return nil } +// UnmarshallableString typedef for builtin string +type UnmarshallableString string + +// UnmarshalText implements the encoding.TextUnmarshaler interface. +// Returns the string +func (s *UnmarshallableString) UnmarshalText(data []byte) error { + *s = UnmarshallableString(data) + return nil +} + // CommonArgs contains the IgnoreUnknown argument // and must be embedded by all Arg structs type CommonArgs struct {