Documentation ¶
Overview ¶
Package structology provides utilities for manage application state with go structs
Index ¶
- Constants
- func GenMarkerFields(t reflect.Type) []reflect.StructField
- func HasSetMarker(t reflect.Type) bool
- func IsSetMarker(tag reflect.StructTag) bool
- func NewSelectors(owner reflect.Type, opts ...SelectorOption) (Selectors, *Marker)
- func ParseTime(layout, input string) (time.Time, error)
- type Marker
- func (p *Marker) CanUseHolder(ptr unsafe.Pointer) bool
- func (p *Marker) EnsureHolder(ptr unsafe.Pointer)
- func (p *Marker) Index(name string) int
- func (p *Marker) IsFieldSet(ptr unsafe.Pointer, name string) bool
- func (p *Marker) IsSet(ptr unsafe.Pointer, index int) bool
- func (p *Marker) Set(ptr unsafe.Pointer, index int, flag bool) error
- func (p *Marker) SetAll(ptr unsafe.Pointer, flag bool) error
- func (p *Marker) Type() reflect.Type
- type Option
- type Options
- type PathOption
- type Selector
- func (s *Selector) Bool(ptr unsafe.Pointer, opts ...PathOption) bool
- func (s *Selector) Float32(ptr unsafe.Pointer, opts ...PathOption) float32
- func (s *Selector) Float64(ptr unsafe.Pointer, opts ...PathOption) float64
- func (s *Selector) Has(ptr unsafe.Pointer, opts ...PathOption) bool
- func (s *Selector) Int(ptr unsafe.Pointer, opts ...PathOption) int
- func (s *Selector) IsAnonymous() bool
- func (s *Selector) Name() string
- func (s *Selector) Path() string
- func (s *Selector) Set(ptr unsafe.Pointer, value interface{}, opts ...PathOption) error
- func (s *Selector) SetBool(ptr unsafe.Pointer, value bool, opts ...PathOption)
- func (s *Selector) SetFloat32(ptr unsafe.Pointer, value float32, opts ...PathOption)
- func (s *Selector) SetFloat64(ptr unsafe.Pointer, value float64, opts ...PathOption)
- func (s *Selector) SetInt(ptr unsafe.Pointer, value int, opts ...PathOption)
- func (s *Selector) SetString(ptr unsafe.Pointer, value string, opts ...PathOption)
- func (s *Selector) SetValue(ptr unsafe.Pointer, value interface{}, opts ...PathOption) (err error)
- func (s *Selector) String(ptr unsafe.Pointer, opts ...PathOption) string
- func (s *Selector) Tag() reflect.StructTag
- func (s *Selector) Type() reflect.Type
- func (s *Selector) Value(ptr unsafe.Pointer, opts ...PathOption) interface{}
- func (s *Selector) Values(ptr unsafe.Pointer, opts ...PathOption) []interface{}
- type SelectorOption
- type Selectors
- type Setter
- type SetterOption
- type State
- func (s *State) Bool(aPath string, pathOptions ...PathOption) (bool, error)
- func (s *State) EnsureMarker()
- func (s *State) Float64(aPath string, pathOptions ...PathOption) (float64, error)
- func (s *State) HasMarker() bool
- func (s *State) MarkerHolder() interface{}
- func (s *State) MergeFrom(from *State) error
- func (s *State) Pointer() unsafe.Pointer
- func (s *State) Selector(aPath string) (*Selector, error)
- func (s *State) SetBool(aPath string, value bool, pathOptions ...PathOption) error
- func (s *State) SetFloat32(aPath string, value float32, pathOptions ...PathOption) error
- func (s *State) SetFloat64(aPath string, value float64, pathOptions ...PathOption) error
- func (s *State) SetInt(aPath string, value int, pathOptions ...PathOption) error
- func (s *State) SetPrimitive(aPath string, value interface{}, pathOptions ...PathOption) error
- func (s *State) SetString(aPath string, value string, pathOptions ...PathOption) error
- func (s *State) SetValue(aPath string, value interface{}, pathOptions ...PathOption) error
- func (s *State) State() interface{}
- func (s *State) StatePtr() interface{}
- func (s *State) String(aPath string, pathOptions ...PathOption) (string, error)
- func (s *State) Sync()
- func (s *State) SyncPointer()
- func (s *State) Type() *StateType
- func (s *State) Value(aPath string, pathOptions ...PathOption) (interface{}, error)
- func (s *State) Values(aPath string, pathOptions ...PathOption) ([]interface{}, error)
- type StateType
- func (s *StateType) HasMarker() bool
- func (s *StateType) IsDefined() bool
- func (s *StateType) Lookup(name string) *Selector
- func (s *StateType) Marker() *Marker
- func (s *StateType) MatchByTag(tagName string) []*Selector
- func (t *StateType) NewState() *State
- func (s *StateType) RootSelectors() []*Selector
- func (s *StateType) Type() reflect.Type
- func (t *StateType) WithValue(value interface{}) *State
Constants ¶
const (
//SetMarkerTag defines set marker tag
SetMarkerTag = "setMarker"
)
Variables ¶
This section is empty.
Functions ¶
func GenMarkerFields ¶
func GenMarkerFields(t reflect.Type) []reflect.StructField
GenMarkerFields generate marker struct fields
func HasSetMarker ¶ added in v0.3.0
HasSetMarker returns true if struct has set marker
func IsSetMarker ¶
func NewSelectors ¶ added in v0.3.0
func NewSelectors(owner reflect.Type, opts ...SelectorOption) (Selectors, *Marker)
NewSelectors creates a selectors for supplied owner types
Types ¶
type Marker ¶
type Marker struct {
// contains filtered or unexported fields
}
Marker field set marker
func (*Marker) EnsureHolder ¶ added in v0.3.0
func (*Marker) IsFieldSet ¶ added in v0.4.0
IsFieldSet returns true if filed has been set
type Option ¶
type Option func(m *Marker)
Option marker option
func WithNoStrict ¶ added in v0.2.0
WithNoStrict create no strict option
type PathOption ¶ added in v0.3.0
type PathOption func(o *pathOptions)
func WithPathIndex ¶ added in v0.3.0
func WithPathIndex(indexes ...int) PathOption
type Selector ¶ added in v0.3.0
type Selector struct { Selectors // contains filtered or unexported fields }
Selector represents struct path selector
func (*Selector) Bool ¶ added in v0.3.0
func (s *Selector) Bool(ptr unsafe.Pointer, opts ...PathOption) bool
func (*Selector) Float32 ¶ added in v0.3.0
func (s *Selector) Float32(ptr unsafe.Pointer, opts ...PathOption) float32
func (*Selector) Float64 ¶ added in v0.3.0
func (s *Selector) Float64(ptr unsafe.Pointer, opts ...PathOption) float64
func (*Selector) Has ¶ added in v0.4.0
func (s *Selector) Has(ptr unsafe.Pointer, opts ...PathOption) bool
func (*Selector) Int ¶ added in v0.3.0
func (s *Selector) Int(ptr unsafe.Pointer, opts ...PathOption) int
func (*Selector) IsAnonymous ¶ added in v0.4.3
func (*Selector) Set ¶ added in v0.3.0
func (s *Selector) Set(ptr unsafe.Pointer, value interface{}, opts ...PathOption) error
Set sets selector value
func (*Selector) SetBool ¶ added in v0.3.0
func (s *Selector) SetBool(ptr unsafe.Pointer, value bool, opts ...PathOption)
SetBool sets selector bool value
func (*Selector) SetFloat32 ¶ added in v0.3.0
func (s *Selector) SetFloat32(ptr unsafe.Pointer, value float32, opts ...PathOption)
SetFloat32 sets selector float32 value
func (*Selector) SetFloat64 ¶ added in v0.3.0
func (s *Selector) SetFloat64(ptr unsafe.Pointer, value float64, opts ...PathOption)
SetFloat64 sets selector float64 value
func (*Selector) SetInt ¶ added in v0.3.0
func (s *Selector) SetInt(ptr unsafe.Pointer, value int, opts ...PathOption)
SetInt sets selector int value
func (*Selector) SetString ¶ added in v0.3.0
func (s *Selector) SetString(ptr unsafe.Pointer, value string, opts ...PathOption)
SetString sets selector string value
func (*Selector) SetValue ¶ added in v0.3.0
func (s *Selector) SetValue(ptr unsafe.Pointer, value interface{}, opts ...PathOption) (err error)
SetValue sets selector value
func (*Selector) String ¶ added in v0.3.0
func (s *Selector) String(ptr unsafe.Pointer, opts ...PathOption) string
type SelectorOption ¶ added in v0.3.0
type SelectorOption func(o *selectorOptions)
SelectorOption represents selector option
func WithCustomizedNames ¶ added in v0.3.0
func WithCustomizedNames(fn func(name string, tag reflect.StructTag) []string) SelectorOption
WithCustomizedNames returns selector option with customized names use by selector indexer
func WithMarkerOption ¶ added in v0.3.0
func WithMarkerOption(opt Option) SelectorOption
WithMarkerOption returns selector option with marker option
type Selectors ¶ added in v0.3.0
Selectors indexed selectors
type Setter ¶ added in v0.6.0
type SetterOption ¶ added in v0.4.3
type SetterOption func(o *setterOptions)
func WithTimeLayout ¶ added in v0.4.3
func WithTimeLayout(timeLayout string) SetterOption
type State ¶ added in v0.3.0
type State struct {
// contains filtered or unexported fields
}
State represents a state
func (*State) Bool ¶ added in v0.3.0
func (s *State) Bool(aPath string, pathOptions ...PathOption) (bool, error)
Bool returns a value for supplied path
func (*State) EnsureMarker ¶ added in v0.4.3
func (s *State) EnsureMarker()
func (*State) Float64 ¶ added in v0.3.0
func (s *State) Float64(aPath string, pathOptions ...PathOption) (float64, error)
func (*State) MarkerHolder ¶ added in v0.4.0
func (s *State) MarkerHolder() interface{}
func (*State) SetBool ¶ added in v0.3.0
func (s *State) SetBool(aPath string, value bool, pathOptions ...PathOption) error
SetBool set bool for supplied state path
func (*State) SetFloat32 ¶ added in v0.3.0
func (s *State) SetFloat32(aPath string, value float32, pathOptions ...PathOption) error
func (*State) SetFloat64 ¶ added in v0.3.0
func (s *State) SetFloat64(aPath string, value float64, pathOptions ...PathOption) error
SetFloat64 set float for supplied state path
func (*State) SetInt ¶ added in v0.3.0
func (s *State) SetInt(aPath string, value int, pathOptions ...PathOption) error
SetInt set int for supplied path
func (*State) SetPrimitive ¶ added in v0.4.0
func (s *State) SetPrimitive(aPath string, value interface{}, pathOptions ...PathOption) error
SetPrimitive sets primitive value
func (*State) SetString ¶ added in v0.3.0
func (s *State) SetString(aPath string, value string, pathOptions ...PathOption) error
SetString set string for supplied state path
func (*State) SetValue ¶ added in v0.3.0
func (s *State) SetValue(aPath string, value interface{}, pathOptions ...PathOption) error
SetValue set state value
func (*State) StatePtr ¶ added in v0.4.3
func (s *State) StatePtr() interface{}
StatePtr return state value
func (*State) String ¶ added in v0.3.0
func (s *State) String(aPath string, pathOptions ...PathOption) (string, error)
Bool returns a value for supplied path
func (*State) Sync ¶ added in v0.4.3
func (s *State) Sync()
Sync syncs value ptr ot value if out of sync
func (*State) SyncPointer ¶ added in v0.6.0
func (s *State) SyncPointer()
SyncPointer syncs value ptr to value
type StateType ¶ added in v0.3.0
type StateType struct {
// contains filtered or unexported fields
}
StateType represents a state type
func NewStateType ¶ added in v0.3.0
func NewStateType(rType reflect.Type, opts ...SelectorOption) *StateType
NewStateType creates a state type
func (*StateType) MatchByTag ¶ added in v0.4.3
MatchByTag matches selector by tag name