Documentation ¶
Overview ¶
Package GoStruct - A framework for type agnostic and recursive data.
Package GoStruct - Snaffooed from https://github.com/fatih/structs
Package GoStruct - Snaffooed from https://github.com/fatih/structs Package GoStruct contains various utilities functions to work with structs.
Package GoStruct - Snaffooed from https://github.com/fatih/structs
Index ¶
- Constants
- Variables
- func AddFloatValues(precision int, refs ...*Reflect) float64
- func AddIntegerValues(refs ...*Reflect) int64
- func FillMap(s interface{}, out map[string]interface{})
- func GetChildGoStruct(ref interface{}, limit int) (*DataTags, *DataTags)
- func GetStructFields(ref interface{}) map[string]string
- func GetStructFieldsAsArray(ref *Reflect) []string
- func GetStructValuesAsArray(ref *Reflect) []string
- func HasZero(s interface{}) bool
- func IsStruct(s interface{}) bool
- func IsZero(s interface{}) bool
- func Map(s interface{}) map[string]interface{}
- func Name(s interface{}) string
- func Names(s interface{}) []string
- func StrSet(src string, dst string) string
- func Values(s interface{}) []interface{}
- func VerifyOptionsRequired(ref interface{}) error
- type DataTags
- type EndPointPath
- func (e *EndPointPath) AddString(path ...string) string
- func (e *EndPointPath) Append(path ...string)
- func (e *EndPointPath) Clear()
- func (e *EndPointPath) Copy() EndPointPath
- func (e *EndPointPath) First() string
- func (e *EndPointPath) Index(index int) string
- func (e *EndPointPath) InsertFirst(s string)
- func (e *EndPointPath) IsBeginsWith(compare string) bool
- func (e *EndPointPath) IsZero() bool
- func (e *EndPointPath) Last() string
- func (e EndPointPath) MarshalJSON() ([]byte, error)
- func (e *EndPointPath) PopLast()
- func (e *EndPointPath) ReplaceFirst(s string)
- func (e *EndPointPath) ShiftLeft(s int64)
- func (e EndPointPath) String() string
- func (e *EndPointPath) Strings() []string
- type Field
- func (f *Field) Field(name string) *Field
- func (f *Field) FieldOk(name string) (*Field, bool)
- func (f *Field) Fields() []*Field
- func (f *Field) IsEmbedded() bool
- func (f *Field) IsExported() bool
- func (f *Field) IsZero() bool
- func (f *Field) Kind() reflect.Kind
- func (f *Field) Name() string
- func (f *Field) Set(val interface{}) error
- func (f *Field) Tag(key string) string
- func (f *Field) Value() interface{}
- func (f *Field) Zero() error
- type GoStruct
- type GoStructParent
- type Reflect
- func (r *Reflect) AsJson() string
- func (r *Reflect) Copy() Reflect
- func (r *Reflect) CopyEndPointPath() EndPointPath
- func (r *Reflect) CountChildren() (int, int)
- func (r *Reflect) EndPointPath() *EndPointPath
- func (r *Reflect) GetDataTableIndexNames() []string
- func (r *Reflect) GetFieldPath() EndPointPath
- func (r *Reflect) GetGoStruct() *DataTags
- func (r *Reflect) GetGoStructCurrent() *Reflect
- func (r *Reflect) GetValueFloat() float64
- func (r *Reflect) HasGoStruct() bool
- func (r *Reflect) Init(parent interface{}, current interface{}, name EndPointPath)
- func (r *Reflect) IsDataTableIndex() bool
- func (r *Reflect) IsDataTableMerge() bool
- func (r *Reflect) IsGoStruct() bool
- func (r *Reflect) IsGoStructForParent() bool
- func (r *Reflect) IsGroup() bool
- func (r *Reflect) IsKnown() bool
- func (r *Reflect) IsNotPointIdReplace() bool
- func (r *Reflect) IsNotTable() bool
- func (r *Reflect) IsPointArrayFlatten() bool
- func (r *Reflect) IsPointIdReplace() bool
- func (r *Reflect) IsPointIgnore() bool
- func (r *Reflect) IsPointIgnoreZero() bool
- func (r *Reflect) IsPointListFlatten() bool
- func (r *Reflect) IsPointTimestampNotZero() bool
- func (r *Reflect) IsPointTimestampZero() bool
- func (r *Reflect) IsPointVariableUnit() bool
- func (r *Reflect) IsPointVirtual() bool
- func (r *Reflect) IsTable() bool
- func (r *Reflect) IsTableChild() (bool, int)
- func (r *Reflect) IsUnknown() bool
- func (r *Reflect) Name() string
- func (r *Reflect) PointGroupName() string
- func (r *Reflect) PointIcon() string
- func (r *Reflect) PointId() string
- func (r *Reflect) PointIgnoreIfChildFromNil() bool
- func (r *Reflect) PointName() string
- func (r *Reflect) PointUpdateFreq() string
- func (r *Reflect) SetByIndex(parent *Reflect, current *Reflect, index int, indexName reflect.Value)
- func (r *Reflect) SetDataTableIndexNames(args ...string)
- func (r *Reflect) SetDataTableIndexTitle(args string)
- func (r *Reflect) SetEndPointPath(epp EndPointPath) *EndPointPath
- func (r *Reflect) SetGoStructOptions(limit int) bool
- func (r *Reflect) SetPointId() EndPointPath
- func (r *Reflect) SetUnit(unit string)
- func (r *Reflect) SetUnitValue(value valueTypes.UnitValue)
- func (r *Reflect) SetUnitValues(value valueTypes.UnitValues)
- func (r *Reflect) SetValue(value interface{})
- func (r *Reflect) SetValuePrecision(precision int)
- func (r Reflect) String() string
- func (r *Reflect) UpdateUnit()
- func (r *Reflect) ValueFirst() *valueTypes.UnitValue
- func (r *Reflect) ValueLast() *valueTypes.UnitValue
- func (r *Reflect) ValueLength() int
- func (r *Reflect) ValueType() string
- func (r *Reflect) ValueUnit() string
- func (r *Reflect) ValuesRange() []valueTypes.UnitValue
- type ReflectArray
- type ReflectArrayRow
- type ReflectMap
- type Required
- type Struct
- func (s *Struct) Field(name string) *Field
- func (s *Struct) FieldOk(name string) (*Field, bool)
- func (s *Struct) Fields() []*Field
- func (s *Struct) FillMap(out map[string]interface{})
- func (s *Struct) HasZero() bool
- func (s *Struct) IsZero() bool
- func (s *Struct) Map() map[string]interface{}
- func (s *Struct) Name() string
- func (s *Struct) Names() []string
- func (s *Struct) Values() []interface{}
- type StructMap
- func (sm *StructMap) Add(Current *Reflect)
- func (sm *StructMap) AddTable(Current *Reflect)
- func (sm *StructMap) AddVirtual(Current *Reflect)
- func (sm *StructMap) Exists(Current *Reflect) bool
- func (sm *StructMap) InitScan(current interface{}, options StructMapOptions)
- func (sm *StructMap) IsEmpty(Current *Reflect) bool
- func (sm *StructMap) IsInvalid(Current *Reflect)
- func (sm *StructMap) IsNil(Current *Reflect) bool
- func (sm *StructMap) IsPointArrayFlatten(Current *Reflect) bool
- func (sm *StructMap) IsPointSplitOn(Current *Reflect) bool
- func (sm *StructMap) IsTable(Current *Reflect) bool
- func (sm *StructMap) IsUnexported(Current *Reflect) bool
- func (sm *StructMap) IsUnsupported(Current *Reflect)
- func (sm *StructMap) PrintDebug(format string, args ...interface{})
- func (sm *StructMap) Process(Child *Reflect) bool
- func (sm *StructMap) Scan(Parent *Reflect, Current *Reflect) *StructMap
- func (sm *StructMap) ScanMap(Parent *Reflect, Current *Reflect) bool
- func (sm *StructMap) ScanSlice(Parent *Reflect, Current *Reflect) bool
- func (sm *StructMap) ScanStruct(Parent *Reflect, Current *Reflect) bool
- type StructMapOptions
- type StructTable
- func (ta *StructTable) AddRow(refs ...*Reflect)
- func (ta *StructTable) CreateTable() (output.Table, error)
- func (ta *StructTable) Get() ReflectArray
- func (ta *StructTable) GetHeaders() []string
- func (ta *StructTable) GetRow(row int) ReflectArrayRow
- func (ta *StructTable) GetValues() StructValues
- func (ta *StructTable) PrintDebug(format string, args ...interface{})
- func (ta *StructTable) Process(area string, name string, Current *Reflect) error
- type StructTables
- type StructValue
- type StructValues
- type StructValuesMap
Constants ¶
const ( // NameGoStruct - Name of field within structure that allows for assigning tags to the parent. // Add like this: // type ResultData []struct { // GoStruct GoStruct.GoStruct `json:"-" DataTable:"true" DataTableSortOn:"UnitConvertId"` // // ... // // } NameGoStruct = "GoStruct" PkgGoStruct = "GoStruct.GoStruct" NameGoStructParent = "GoStructParent" PkgGoStructParent = "GoStruct.GoStructParent" // PointId - Point id in the form p\d+ or \d+ or free-form text. PointId = "PointId" // PointIdFrom - Searches current structure for field value to use for naming when hitting a slice, (as opposed to using an index). PointIdFrom = "PointIdFrom" // PointIdFromChild - Searches child for field value to use for naming when hitting a slice, (as opposed to using an index). PointIdFromChild = "PointIdFromChild" // PointIdReplace - Replace PointNameFrom instead of append. PointIdReplace = "PointIdReplace" // PointParentId - Associated parent of point. PointParentId = "PointParentId" // PointUpdateFreq - Point update frequency - Total, Yearly, Monthly, Day. PointUpdateFreq = "PointUpdateFreq" UpdateFreqInstant = "instant" UpdateFreq5Mins = "5mins" UpdateFreq15Mins = "15mins" UpdateFreq30Mins = "30mins" UpdateFreqBoot = "boot" UpdateFreqDay = "daily" UpdateFreqMonth = "monthly" UpdateFreqYear = "yearly" UpdateFreqTotal = "total" // PointValueType - Value type of point: energy, date, battery, temperature. PointValueType = "PointValueType" // PointUnit - Units: Wh, kWh, C, h. PointUnit = "PointUnit" // PointUnitFrom - Get PointUnit from another field structure. PointUnitFrom = "PointUnitFrom" // PointUnitFromParent - Get PointUnit from another parent field structure. PointUnitFromParent = "PointUnitFromParent" // PointVariableUnit - Will be any number of units - used mainly in table display. PointVariableUnit = "PointVariableUnit" // PointIgnore - Ignore this point. PointIgnore = "PointIgnore" // PointIgnoreIfNil - Ignore this point if a child is nil or empty. PointIgnoreIfNil = "PointIgnoreIfNil" // PointIgnoreIfChildFromNil - Ignore this point if a child is nil or empty. PointIgnoreIfChildFromNil = "PointIgnoreIfChildFromNil" // PointIgnoreZero - Ignore arrays with zero size, (default true). PointIgnoreZero = "PointIgnoreZero" // PointAliasTo - Alias this point to another point. PointAliasTo = "PointAliasTo" // PointAliasFrom - Alias this point from another point. PointAliasFrom = "PointAliasFrom" // PointVirtual - Create a Virtual point alias. PointVirtual = "PointVirtual" // PointVirtualShift - Create a Virtual point alias. PointVirtualShift = "PointVirtualShift" // PointGroupName - Point group name. PointGroupName = "PointGroupName" // PointGroupNameFrom - Get PointGroupName from another field structure. PointGroupNameFrom = "PointGroupNameFrom" // PointName - Human-readable name of point. PointName = "PointName" // PointIcon - Icon of point. PointIcon = "PointIcon" // PointNameDateFormat - Date format when using PointNameFrom, (if the field is a time.Time type). PointNameDateFormat = "PointNameDateFormat" // PointArrayFlatten - Flatten an array into a string. EG: ["one", "two", "three"] PointArrayFlatten = "PointArrayFlatten" // PointSplitForce - Force a point to split. PointSplitForce = "PointSplitForce" // PointSplitOn - Split a point into an array separating by defined string. PointSplitOn = "PointSplitOn" // PointSplitOnType - What valueTypes will be used for a split. PointSplitOnType = "PointSplitOnType" // PointTimestampFrom - Pull timestamp from another field structure. PointTimestampFrom = "PointTimestampFrom" // PointValueReplace - Search endpoint value and replace with string contained in PointValueReplaceWith PointValueReplace = "PointValueReplace" // PointValueReplaceWith - PointValueReplaceWith = "PointValueReplaceWith" // PointDevice - Define a PointDevice for this point. PointDevice = "PointDevice" // PointDeviceFrom - Reference PointDevice from another sibling. PointDeviceFrom = "PointDeviceFrom" // PointDeviceFromParent - Reference PointDevice from a parent. PointDeviceFromParent = "PointDeviceFromParent" // IsDataTable - This entity is a data table - Will only traverse down one child. IsDataTable = "DataTable" // DataTableChild - Will be included in table listings. DataTableChild = "DataTableChild" // DataTableId - Table id, (defaults to Json tag). DataTableId = "DataTableId" // DataTableName - Table Name, (defaults to DataTableId). DataTableName = "DataTableName" // DataTableTitle - Table Title, (defaults to DataTableId in name format). DataTableTitle = "DataTableTitle" // DataTableMerge - Merge rows together - useful for when we use, for EG: []valueTypes.Float DataTableMerge = "DataTableMerge" // DataTableIndex - Show index on table. DataTableIndex = "DataTableIndex" // DataTableIndexTitle - Show index title on table. DataTableIndexTitle = "DataTableIndexTitle" // DataTableIndexNames - Use this comma separated list of names to replace index numbers. DataTableIndexNames = "DataTableIndexNames" // DataTableSortOn - Sort table using this Field. DataTableSortOn = "DataTableSortOn" // DataTablePivot - Pivot the table. DataTablePivot = "DataTablePivot" // PointListFlatten - Flatten a point into a string - only for list display. PointListFlatten = "PointListFlatten" )
Variables ¶
var ( // DefaultTagName is the default tag name for struct fields which provides // a more granular to tweak certain structs. Lookup the necessary functions // for more info. DefaultTagName = "structs" // struct's field default tag name )
Functions ¶
func AddFloatValues ¶
func AddIntegerValues ¶
func FillMap ¶
func FillMap(s interface{}, out map[string]interface{})
FillMap is the same as Map. Instead of returning the output, it fills the given map.
func GetChildGoStruct ¶
func GetStructFields ¶
func GetStructFieldsAsArray ¶
func GetStructValuesAsArray ¶
func HasZero ¶
func HasZero(s interface{}) bool
HasZero returns true if any field is equal to a zero value. For more info refer to Struct types HasZero() method. It panics if s's kind is not struct.
func IsStruct ¶
func IsStruct(s interface{}) bool
IsStruct returns true if the given variable is a struct or a pointer to struct.
func IsZero ¶
func IsZero(s interface{}) bool
IsZero returns true if all fields is equal to a zero value. For more info refer to Struct types IsZero() method. It panics if s's kind is not struct.
func Map ¶
func Map(s interface{}) map[string]interface{}
Map converts the given struct to a map[string]interface{}. For more info refer to Struct types Map() method. It panics if s's kind is not struct.
func Name ¶
func Name(s interface{}) string
Name returns the structs's type name within its package. It returns an empty string for unnamed types. It panics if s's kind is not struct.
func Names ¶
func Names(s interface{}) []string
Names returns a slice of field names. For more info refer to Struct types Names() method. It panics if s's kind is not struct.
func Values ¶
func Values(s interface{}) []interface{}
Values converts the given struct to a []interface{}. For more info refer to Struct types Values() method. It panics if s's kind is not struct.
func VerifyOptionsRequired ¶
func VerifyOptionsRequired(ref interface{}) error
VerifyOptionsRequired Verify fields within the structure are required.
Types ¶
type DataTags ¶
type DataTags struct { Endpoint EndPointPath `json:"endpoint,omitempty"` Required bool `json:"required"` Json string `json:"json,omitempty"` PointDevice string `json:"point_device,omitempty"` PointDeviceFrom string `json:"point_device_from,omitempty"` PointDeviceFromParent string `json:"point_device_from_parent,omitempty"` PointId string `json:"point_id,omitempty"` PointUpdateFreq string `json:"point_update_freq,omitempty"` PointValueType string `json:"point_value_type,omitempty"` PointAliasTo string `json:"point_alias_to,omitempty"` PointVirtual bool `json:"point_virtual,omitempty"` PointVirtualShift int64 `json:"point_virtual_shift,omitempty"` PointTimestamp time.Time `json:"point_timestamp,omitempty"` PointTimestampFrom string `json:"point_timestamp_from,omitempty"` PointUnit string `json:"point_unit,omitempty"` PointUnitFrom string `json:"point_unit_from,omitempty"` PointUnitFromParent string `json:"point_unit_from_parent,omitempty"` PointVariableUnit bool `json:"point_variable_unit,omitempty"` PointName string `json:"point_name,omitempty"` PointIdReplace bool `json:"point_name_append,omitempty"` PointIdFrom string `json:"point_id_from,omitempty"` PointIdFromChild string `json:"point_name_from_child,omitempty"` // PointIdFromParent string `json:"point_name_from_parent,omitempty"` PointNameDateFormat string `json:"point_name_date_format,omitempty"` PointIcon string `json:"point_icon,omitempty"` PointIgnore bool `json:"point_ignore,omitempty"` PointIgnoreZero bool `json:"point_ignore_zero,omitempty"` PointIgnoreIfNil string `json:"point_ignore_if_nil,omitempty"` PointIgnoreIfChildFromNil string `json:"point_ignore_if_child_nil,omitempty"` PointGroupName string `json:"point_group_name,omitempty"` PointGroupNameFrom string `json:"point_group_name_from,omitempty"` PointArrayFlatten bool `json:"point_array_flatten,omitempty"` PointListFlatten bool `json:"point_list_flatten,omitempty"` PointSplitOn string `json:"point_split_on,omitempty"` PointSplitOnType string `json:"point_split_on_type,omitempty"` PointValueReplace string `json:"point_value_replace,omitempty"` PointValueReplaceWith string `json:"point_value_replace_with,omitempty"` DataTable bool `json:"data_table,omitempty"` DataTableChild bool `json:"data_table_child,omitempty"` DataTablePivot bool `json:"data_table_pivot,omitempty"` DataTableId string `json:"data_table_id,omitempty"` DataTableName string `json:"data_table_name,omitempty"` DataTableTitle string `json:"data_table_title,omitempty"` DataTableMerge bool `json:"data_table_merge,omitempty"` DataTableIndex bool `json:"data_table_show_index,omitempty"` DataTableIndexNames []string `json:"data_table_index_names,omitempty"` DataTableSortOn string `json:"data_table_sort_on,omitempty"` DataTableIndexTitle string `json:"data_table_index_title,omitempty"` ValueType string `json:"value_type,omitempty"` ValueKind string `json:"value_kind,omitempty"` StrBool tagStrings `json:"-"` }
type EndPointPath ¶
type EndPointPath struct {
// contains filtered or unexported fields
}
func NewEndPointPath ¶
func NewEndPointPath(path ...string) EndPointPath
func (*EndPointPath) AddString ¶
func (e *EndPointPath) AddString(path ...string) string
func (*EndPointPath) Append ¶
func (e *EndPointPath) Append(path ...string)
func (*EndPointPath) Clear ¶
func (e *EndPointPath) Clear()
func (*EndPointPath) Copy ¶
func (e *EndPointPath) Copy() EndPointPath
func (*EndPointPath) First ¶
func (e *EndPointPath) First() string
func (*EndPointPath) Index ¶
func (e *EndPointPath) Index(index int) string
func (*EndPointPath) InsertFirst ¶
func (e *EndPointPath) InsertFirst(s string)
func (*EndPointPath) IsBeginsWith ¶
func (e *EndPointPath) IsBeginsWith(compare string) bool
func (*EndPointPath) IsZero ¶
func (e *EndPointPath) IsZero() bool
func (*EndPointPath) Last ¶
func (e *EndPointPath) Last() string
func (EndPointPath) MarshalJSON ¶
func (e EndPointPath) MarshalJSON() ([]byte, error)
MarshalJSON - Convert value to JSON
func (*EndPointPath) PopLast ¶
func (e *EndPointPath) PopLast()
func (*EndPointPath) ReplaceFirst ¶
func (e *EndPointPath) ReplaceFirst(s string)
func (*EndPointPath) ShiftLeft ¶
func (e *EndPointPath) ShiftLeft(s int64)
func (EndPointPath) String ¶
func (e EndPointPath) String() string
func (*EndPointPath) Strings ¶
func (e *EndPointPath) Strings() []string
type Field ¶
type Field struct {
// contains filtered or unexported fields
}
Field represents a single struct field that encapsulates high level functions around the field.
func Fields ¶
func Fields(s interface{}) []*Field
Fields returns a slice of *Field. For more info refer to Struct types Fields() method. It panics if s's kind is not struct.
func (*Field) Field ¶
Field returns the field from a nested struct. It panics if the nested struct is not exported or if the field was not found.
func (*Field) FieldOk ¶
FieldOk returns the field from a nested struct. The boolean returns whether the field was found (true) or not (false).
func (*Field) Fields ¶
Fields returns a slice of Fields. This is particular handy to get the fields of a nested struct . A struct tag with the content of "-" ignores the checking of that particular field. Example:
// Field is ignored by this package. Field *http.Request `structs:"-"`
It panics if field is not exported or if field's kind is not struct
func (*Field) IsEmbedded ¶
IsEmbedded returns true if the given field is an anonymous field (embedded)
func (*Field) IsExported ¶
IsExported returns true if the given field is exported.
func (*Field) IsZero ¶
IsZero returns true if the given field is not initialized (has a zero value). It panics if the field is not exported.
func (*Field) Set ¶
Set sets the field to given value v. It returns an error if the field is not settable (not addressable or not exported) or if the given value's type doesn't match the fields type.
func (*Field) Tag ¶
Tag returns the value associated with key in the tag string. If there is no such key in the tag, Tag returns the empty string.
type GoStructParent ¶
type GoStructParent bool
type Reflect ¶
type Reflect struct { FieldPath EndPointPath ParentReflect *Reflect CurrentReflect *Reflect ChildReflect []*Reflect ChildReflectMap map[string]*Reflect Valid bool DataStructure DataTags GoStructs struct { Parent *DataTags Current *DataTags } Interface interface{} IsNil bool IsExported bool IsOk bool Value valueTypes.UnitValues InterfaceValue interface{} IsStart bool Index int Length int FieldName string Kind reflect.Kind TypeOf reflect.Type ValueOf reflect.Value FieldTo reflect.StructField FieldVo reflect.Value // contains filtered or unexported fields }
Reflect - Combines all the common reflect work into one package So we don't have to keep repeating ourselves.
func (*Reflect) CopyEndPointPath ¶
func (r *Reflect) CopyEndPointPath() EndPointPath
func (*Reflect) CountChildren ¶
func (*Reflect) EndPointPath ¶
func (r *Reflect) EndPointPath() *EndPointPath
func (*Reflect) GetDataTableIndexNames ¶
func (*Reflect) GetFieldPath ¶
func (r *Reflect) GetFieldPath() EndPointPath
func (*Reflect) GetGoStruct ¶
func (*Reflect) GetGoStructCurrent ¶
func (*Reflect) GetValueFloat ¶
func (*Reflect) HasGoStruct ¶
func (*Reflect) Init ¶
func (r *Reflect) Init(parent interface{}, current interface{}, name EndPointPath)
func (*Reflect) IsDataTableIndex ¶
func (*Reflect) IsDataTableMerge ¶
func (*Reflect) IsGoStruct ¶
func (*Reflect) IsGoStructForParent ¶
func (*Reflect) IsNotPointIdReplace ¶
func (*Reflect) IsNotTable ¶
func (*Reflect) IsPointArrayFlatten ¶
func (*Reflect) IsPointIdReplace ¶
func (*Reflect) IsPointIgnore ¶
func (*Reflect) IsPointIgnoreZero ¶
func (*Reflect) IsPointListFlatten ¶
func (*Reflect) IsPointTimestampNotZero ¶
func (*Reflect) IsPointTimestampZero ¶
func (*Reflect) IsPointVariableUnit ¶
func (*Reflect) IsPointVirtual ¶
func (*Reflect) IsTableChild ¶
func (*Reflect) PointGroupName ¶
func (*Reflect) PointIgnoreIfChildFromNil ¶
func (*Reflect) PointUpdateFreq ¶
func (*Reflect) SetByIndex ¶
func (*Reflect) SetDataTableIndexNames ¶
func (*Reflect) SetDataTableIndexTitle ¶
func (*Reflect) SetEndPointPath ¶
func (r *Reflect) SetEndPointPath(epp EndPointPath) *EndPointPath
func (*Reflect) SetGoStructOptions ¶
SetGoStructOptions - Copies and updates DataTags from a GoStruct object.
func (*Reflect) SetPointId ¶
func (r *Reflect) SetPointId() EndPointPath
SetPointId - Sets the EndPointPath based off struct tags?
func (*Reflect) SetUnitValue ¶
func (r *Reflect) SetUnitValue(value valueTypes.UnitValue)
func (*Reflect) SetUnitValues ¶
func (r *Reflect) SetUnitValues(value valueTypes.UnitValues)
func (*Reflect) SetValuePrecision ¶
func (*Reflect) UpdateUnit ¶
func (r *Reflect) UpdateUnit()
func (*Reflect) ValueFirst ¶
func (r *Reflect) ValueFirst() *valueTypes.UnitValue
func (*Reflect) ValueLast ¶
func (r *Reflect) ValueLast() *valueTypes.UnitValue
func (*Reflect) ValueLength ¶
func (*Reflect) ValuesRange ¶
func (r *Reflect) ValuesRange() []valueTypes.UnitValue
type ReflectArray ¶
type ReflectArray []ReflectArrayRow
func (*ReflectArray) AddRow ¶
func (ta *ReflectArray) AddRow(refs ...*Reflect) ReflectArray
func (*ReflectArray) GetRow ¶
func (ta *ReflectArray) GetRow(row int) ReflectArrayRow
type ReflectArrayRow ¶
type ReflectArrayRow []*Reflect
type ReflectMap ¶
type Required ¶
type Required []string
func GetOptionsRequired ¶
func GetOptionsRequired(ref interface{}) Required
GetOptionsRequired Get field options within the structure that are required.
func (*Required) IsNotRequired ¶
func (*Required) IsRequired ¶
type Struct ¶
type Struct struct { TagName string // contains filtered or unexported fields }
Struct encapsulates a struct type to provide several high level functions around the struct.
func New ¶
func New(s interface{}) *Struct
New returns a new *Struct with the struct s. It panics if the s's kind is not struct.
func (*Struct) Field ¶
Field returns a new Field struct that provides several high level functions around a single struct field entity. It panics if the field is not found.
func (*Struct) FieldOk ¶
FieldOk returns a new Field struct that provides several high level functions around a single struct field entity. The boolean returns true if the field was found.
func (*Struct) Fields ¶
Fields returns a slice of Fields. A struct tag with the content of "-" ignores the checking of that particular field. Example:
// Field is ignored by this package. Field bool `structs:"-"`
It panics if s's kind is not struct.
func (*Struct) FillMap ¶
FillMap is the same as Map. Instead of returning the output, it fills the given map.
func (*Struct) HasZero ¶
HasZero returns true if a field in a struct is not initialized (zero value). A struct tag with the content of "-" ignores the checking of that particular field. Example:
// Field is ignored by this package. Field bool `structs:"-"`
A value with the option of "omitnested" stops iterating further if the type is a struct. Example:
// Field is not processed further by this package. Field time.Time `structs:"myName,omitnested"` Field *http.Request `structs:",omitnested"`
Note that only exported fields of a struct can be accessed, non exported fields will be neglected. It panics if s's kind is not struct.
func (*Struct) IsZero ¶
IsZero returns true if all fields in a struct is a zero value (not initialized) A struct tag with the content of "-" ignores the checking of that particular field. Example:
// Field is ignored by this package. Field bool `structs:"-"`
A value with the option of "omitnested" stops iterating further if the type is a struct. Example:
// Field is not processed further by this package. Field time.Time `structs:"myName,omitnested"` Field *http.Request `structs:",omitnested"`
Note that only exported fields of a struct can be accessed, non exported fields will be neglected. It panics if s's kind is not struct.
func (*Struct) Map ¶
Map converts the given struct to a map[string]interface{}, where the keys of the map are the field names and the values of the map the associated values of the fields. The default key string is the struct field name but can be changed in the struct field's tag value. The "structs" key in the struct's field tag value is the key name. Example:
// Field appears in map as key "myName". Name string `structs:"myName"`
A tag value with the content of "-" ignores that particular field. Example:
// Field is ignored by this package. Field bool `structs:"-"`
A tag value with the content of "string" uses the stringer to get the value. Example:
// The value will be output of Animal's String() func. // Map will panic if Animal does not implement String(). Field *Animal `structs:"field,string"`
A tag value with the option of "flatten" used in a struct field is to flatten its fields in the output map. Example:
// The FieldStruct's fields will be flattened into the output map. FieldStruct time.Time `structs:",flatten"`
A tag value with the option of "omitnested" stops iterating further if the type is a struct. Example:
// Field is not processed further by this package. Field time.Time `structs:"myName,omitnested"` Field *http.Request `structs:",omitnested"`
A tag value with the option of "omitempty" ignores that particular field if the field value is empty. Example:
// Field appears in map as key "myName", but the field is // skipped if empty. Field string `structs:"myName,omitempty"` // Field appears in map as key "Field" (the default), but // the field is skipped if empty. Field string `structs:",omitempty"`
Note that only exported fields of a struct can be accessed, non exported fields will be neglected.
func (*Struct) Name ¶
Name returns the structs's type name within its package. For more info refer to Name() function.
func (*Struct) Names ¶
Names returns a slice of field names. A struct tag with the content of "-" ignores the checking of that particular field. Example:
// Field is ignored by this package. Field bool `structs:"-"`
It panics if s's kind is not struct.
func (*Struct) Values ¶
func (s *Struct) Values() []interface{}
Values converts the given s struct's field values to a []interface{}. A struct tag with the content of "-" ignores the that particular field. Example:
// Field is ignored by this package. Field int `structs:"-"`
A value with the option of "omitnested" stops iterating further if the type is a struct. Example:
// Fields is not processed further by this package. Field time.Time `structs:",omitnested"` Field *http.Request `structs:",omitnested"`
A tag value with the option of "omitempty" ignores that particular field and is not added to the values if the field value is empty. Example:
// Field is skipped if empty Field string `structs:",omitempty"`
Note that only exported fields of a struct can be accessed, non exported fields will be neglected.
type StructMap ¶
type StructMap struct { StructMapOptions SortOn string Start *Reflect Map map[string]*Reflect TableMap map[string]*Reflect VirtualMap map[string]*Reflect Error error // contains filtered or unexported fields }
func (*StructMap) AddVirtual ¶
func (*StructMap) InitScan ¶
func (sm *StructMap) InitScan(current interface{}, options StructMapOptions)
func (*StructMap) IsPointArrayFlatten ¶
func (*StructMap) IsPointSplitOn ¶
func (*StructMap) IsUnexported ¶
func (*StructMap) IsUnsupported ¶
func (*StructMap) PrintDebug ¶
type StructMapOptions ¶
type StructMapOptions struct { StartAt string Name EndPointPath TimeStamp time.Time Debug bool AddUnexported bool // Add unexported values, (default: false). AddUnsupported bool // Add unsupported types, (default: false). AddInvalid bool // Add invalid types, (default: false). AddEmpty bool // Add empty values, (default: false). AddNil bool // Add nil values, (default: false). }
type StructTable ¶
type StructTable struct { Area string Name string Current *Reflect MapName string Reflects ReflectArray Values StructValues Table output.Table SortOn string ShowIndex bool IndexTitle string IsValid bool Columns []string Rows int Cols int ActualRows int ActualCols int Debug bool Error error }
func (*StructTable) AddRow ¶
func (ta *StructTable) AddRow(refs ...*Reflect)
func (*StructTable) CreateTable ¶
func (ta *StructTable) CreateTable() (output.Table, error)
func (*StructTable) Get ¶
func (ta *StructTable) Get() ReflectArray
func (*StructTable) GetHeaders ¶
func (ta *StructTable) GetHeaders() []string
func (*StructTable) GetRow ¶
func (ta *StructTable) GetRow(row int) ReflectArrayRow
func (*StructTable) GetValues ¶
func (ta *StructTable) GetValues() StructValues
func (*StructTable) PrintDebug ¶
func (ta *StructTable) PrintDebug(format string, args ...interface{})
type StructTables ¶
type StructTables map[string]*StructTable
func (*StructTables) GetTableNames ¶
func (sm *StructTables) GetTableNames() []string
type StructValue ¶
type StructValue map[string]valueTypes.UnitValue
type StructValues ¶
type StructValues []StructValue
func (*StructValues) GetCell ¶
func (ta *StructValues) GetCell(row int, col string) valueTypes.UnitValue
type StructValuesMap ¶
type StructValuesMap map[string]StructValues
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package gojson - generates go struct defintions from JSON documents
|
Package gojson - generates go struct defintions from JSON documents |