pkg/types: Add UnmarshallableString type
authorTom Denham <tom@tomdee.co.uk>
Wed, 1 Jun 2016 00:12:40 +0000 (17:12 -0700)
committerTom Denham <tom@tomdee.co.uk>
Thu, 9 Jun 2016 21:45:58 +0000 (14:45 -0700)
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.

pkg/types/args.go

index 3b667b0..66dcf9e 100644 (file)
@@ -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 {