You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
MakeStringSetter()
returns a function that can be used to assing to reflect.Value given a
string value. It can handle arrays and slices (splits strings on commas).
Parsing struct tags
Use SplitTag() to break a struct
tag into it's elements and then use Tag.Fill()
to parse it into a struct.
For example:
typeTagInfostruct {
Namestring`pt:"0"`// positional, first argumentTrainbool`pt:"train"`// boolean: true: "train", "train=true"; false: "!train", "train=false"Countint`pt:"count"`// integer value will be parsed
}
st:=reflect.StructTag(`foo:"bar,!train,count=9"`)
vartagInfoTagInfoerr:=GetTag(st, "foo").Fill(&tagInfo)
// tagInfo.Name will be "bar"// tagInfo.Train will be false// tagInfo.Count will be 9
Type names
The TypeName() function exists to disambiguate between type names that are
versioned. reflect.Type.String() will hides package versions. This doesn't
matter unless you've, unfortunately, imported multiple versions of the same
package.
Default filler
The FillInDefaultValues() function will look at for a struct tag named "default"
and use that value to fill in values where no value has been set.
Development status
Reflectutils is used by several packages. Backwards compatability is expected.
About
Golang utility functions for working with reflection