Documentation ¶
Overview ¶
Package onchg implements values with a hook function that handles value changes. First the hook is called before a change is made with check=true. With check==true the hook decides if it blocks the set operation. To block the set operation, the hook returns 0. Otherwise the hook provides the change flags for the Set method. The flags from the hook are overridden if non-zero flags are passed to the value's Set method. If the hook is nil all Set methods of this package behave exactly like their chgv-package counterparts.
Set Methods ¶
TODO: describe principle of Set methods.
Hook Functions ¶
TODO: describe principle of hook functions.
Example ¶
user := struct { Name String Logins Int }{ Name: *NewString("John Doe", ChgFlag(1).String), Logins: *NewInt(0, func(_ *Int, o, n int, check bool) change.Flags { if !check { fmt.Printf("changed logins from %d to %d\n", o, n) } return 2 }), } chg := user.Name.Set("John Doe", 0) chg |= user.Logins.Set(1, 0) fmt.Printf("Changes: 0b%b\n", chg) if chg&1 == 0 { fmt.Println("Name did not change") } else { fmt.Println("Name changed") }
Output: changed logins from 0 to 1 Changes: 0b10 Name did not change
Index ¶
- type Bool
- type BoolHook
- type BoolMultiHook
- type Byte
- type ByteHook
- type ByteMultiHook
- type ChgFlag
- func (chg ChgFlag) Bool(src *Bool, _, _ bool, _ bool) change.Flags
- func (chg ChgFlag) Byte(src *Byte, _, _ byte, _ bool) change.Flags
- func (chg ChgFlag) Complex128(src *Complex128, _, _ complex128, _ bool) change.Flags
- func (chg ChgFlag) Complex64(src *Complex64, _, _ complex64, _ bool) change.Flags
- func (chg ChgFlag) Duration(src *Duration, _, _ bool, _ bool) change.Flags
- func (chg ChgFlag) Float32(src *Float32, _, _ float32, _ bool) change.Flags
- func (chg ChgFlag) Float64(src *Float64, _, _ float64, _ bool) change.Flags
- func (chg ChgFlag) Int(src *Int, _, _ int, _ bool) change.Flags
- func (chg ChgFlag) Int16(src *Int16, _, _ int16, _ bool) change.Flags
- func (chg ChgFlag) Int32(src *Int32, _, _ int32, _ bool) change.Flags
- func (chg ChgFlag) Int64(src *Int64, _, _ int64, _ bool) change.Flags
- func (chg ChgFlag) Int8(src *Int8, _, _ int8, _ bool) change.Flags
- func (chg ChgFlag) Rune(src *Rune, _, _ rune, _ bool) change.Flags
- func (chg ChgFlag) String(src *String, _, _ string, _ bool) change.Flags
- func (chg ChgFlag) Time(src *Time, _, _ bool, _ bool) change.Flags
- func (chg ChgFlag) Uint(src *Uint, _, _ uint, _ bool) change.Flags
- func (chg ChgFlag) Uint16(src *Uint16, _, _ uint16, _ bool) change.Flags
- func (chg ChgFlag) Uint32(src *Uint32, _, _ uint32, _ bool) change.Flags
- func (chg ChgFlag) Uint64(src *Uint64, _, _ uint64, _ bool) change.Flags
- func (chg ChgFlag) Uint8(src *Uint8, _, _ uint8, _ bool) change.Flags
- func (chg ChgFlag) UintPtr(src *UintPtr, _, _ uintptr, _ bool) change.Flags
- type Complex128
- type Complex128Hook
- type Complex128MultiHook
- type Complex64
- type Complex64Hook
- type Complex64MultiHook
- type Duration
- type DurationHook
- type DurationMultiHook
- type Float32
- type Float32Hook
- type Float32MultiHook
- type Float64
- type Float64Hook
- type Float64MultiHook
- type Int
- type Int16
- type Int16Hook
- type Int16MultiHook
- type Int32
- type Int32Hook
- type Int32MultiHook
- type Int64
- type Int64Hook
- type Int64MultiHook
- type Int8
- type Int8Hook
- type Int8MultiHook
- type IntHook
- type IntMultiHook
- type Rune
- type RuneHook
- type RuneMultiHook
- type String
- type StringHook
- type StringMultiHook
- type Time
- type TimeHook
- type TimeMultiHook
- type Uint
- type Uint16
- type Uint16Hook
- type Uint16MultiHook
- type Uint32
- type Uint32Hook
- type Uint32MultiHook
- type Uint64
- type Uint64Hook
- type Uint64MultiHook
- type Uint8
- type Uint8Hook
- type Uint8MultiHook
- type UintHook
- type UintMultiHook
- type UintPtr
- type UintPtrHook
- type UintPtrMultiHook
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bool ¶
type Bool struct {
// contains filtered or unexported fields
}
Bool tracks changes of bool values with a hook and Flags. See also onchg package documentation.
type BoolMultiHook ¶ added in v0.3.0
type BoolMultiHook []BoolHook
type Byte ¶
type Byte struct {
// contains filtered or unexported fields
}
Byte tracks changes of bool values with a hook and Flags. See also onchg package documentation.
type ByteMultiHook ¶ added in v0.3.0
type ByteMultiHook []ByteHook
type ChgFlag ¶
ChgFlag is used to provide hooks that always return a Flags value. It is used to provide default Flags when the caller of a Set operation passes 0 Flags. Each method of ChgFlag is a type specific hook for a change-detectable value in package onchg.
func (ChgFlag) Complex128 ¶
func (chg ChgFlag) Complex128(src *Complex128, _, _ complex128, _ bool) change.Flags
Complex128 returns chg as change.Flags
type Complex128 ¶
type Complex128 struct {
// contains filtered or unexported fields
}
Complex128 tracks changes of bool values with a hook and Flags. See also onchg package documentation.
func NewComplex128 ¶
func NewComplex128(init complex128, hook Complex128Hook) *Complex128
NewComplex128 creates a change-detectable Complex128. See also section Hook Funtions.
func (Complex128) Get ¶
func (cv Complex128) Get() complex128
Get returns the current complex128 value.
func (*Complex128) Reset ¶
func (cv *Complex128) Reset(v complex128, hook Complex128Hook) (complex128, Complex128Hook)
Reset does not call a hook, even if the value changes. See also section Hook Funtions.
func (*Complex128) Set ¶
func (cv *Complex128) Set(v complex128, chg change.Flags) change.Flags
Set the value of cv to v. See also section Set Methods.
type Complex128Hook ¶
type Complex128Hook func(src *Complex128, ov, nv complex128, check bool) change.Flags
See section Hook Funtions.
type Complex128MultiHook ¶ added in v0.3.0
type Complex128MultiHook []Complex128Hook
func (Complex128MultiHook) Update ¶ added in v0.3.0
func (mh Complex128MultiHook) Update(src *Complex128, ov, nv complex128, check bool) (chg change.Flags)
type Complex64 ¶
type Complex64 struct {
// contains filtered or unexported fields
}
Complex64 tracks changes of bool values with a hook and Flags. See also onchg package documentation.
func NewComplex64 ¶
func NewComplex64(init complex64, hook Complex64Hook) *Complex64
NewComplex64 creates a change-detectable Complex64. See also section Hook Funtions.
func (*Complex64) Reset ¶
func (cv *Complex64) Reset(v complex64, hook Complex64Hook) (complex64, Complex64Hook)
Reset does not call a hook, even if the value changes. See also section Hook Funtions.
type Complex64Hook ¶
See section Hook Funtions.
type Complex64MultiHook ¶ added in v0.3.0
type Complex64MultiHook []Complex64Hook
type Duration ¶ added in v0.2.0
type Duration struct {
// contains filtered or unexported fields
}
Duration tracks changes of bool values with a hook and Flags. See also onchg package documentation.
func NewDuration ¶ added in v0.2.0
func NewDuration(init time.Duration, hook DurationHook) *Duration
func (*Duration) Reset ¶ added in v0.2.0
func (cv *Duration) Reset(v time.Duration, hook DurationHook) (time.Duration, DurationHook)
type DurationHook ¶ added in v0.2.0
type DurationMultiHook ¶ added in v0.3.0
type DurationMultiHook []DurationHook
type Float32 ¶
type Float32 struct {
// contains filtered or unexported fields
}
Float32 tracks changes of bool values with a hook and Flags. See also onchg package documentation.
func NewFloat32 ¶
func NewFloat32(init float32, hook Float32Hook) *Float32
NewFloat32 creates a change-detectable Float32. See also section Hook Funtions.
func (*Float32) Reset ¶
func (cv *Float32) Reset(v float32, hook Float32Hook) (float32, Float32Hook)
Reset does not call a hook, even if the value changes. See also section Hook Funtions.
type Float32Hook ¶
See section Hook Funtions.
type Float32MultiHook ¶ added in v0.3.0
type Float32MultiHook []Float32Hook
type Float64 ¶
type Float64 struct {
// contains filtered or unexported fields
}
Float64 tracks changes of bool values with a hook and Flags. See also onchg package documentation.
func NewFloat64 ¶
func NewFloat64(init float64, hook Float64Hook) *Float64
NewFloat64 creates a change-detectable Float64. See also section Hook Funtions.
func (*Float64) Reset ¶
func (cv *Float64) Reset(v float64, hook Float64Hook) (float64, Float64Hook)
Reset does not call a hook, even if the value changes. See also section Hook Funtions.
type Float64Hook ¶
See section Hook Funtions.
type Float64MultiHook ¶ added in v0.3.0
type Float64MultiHook []Float64Hook
type Int ¶
type Int struct {
// contains filtered or unexported fields
}
Int tracks changes of bool values with a hook and Flags. See also onchg package documentation.
type Int16 ¶
type Int16 struct {
// contains filtered or unexported fields
}
Int16 tracks changes of bool values with a hook and Flags. See also onchg package documentation.
type Int16MultiHook ¶ added in v0.3.0
type Int16MultiHook []Int16Hook
type Int32 ¶
type Int32 struct {
// contains filtered or unexported fields
}
Int32 tracks changes of bool values with a hook and Flags. See also onchg package documentation.
type Int32MultiHook ¶ added in v0.3.0
type Int32MultiHook []Int32Hook
type Int64 ¶
type Int64 struct {
// contains filtered or unexported fields
}
Int64 tracks changes of bool values with a hook and Flags. See also onchg package documentation.
type Int64MultiHook ¶ added in v0.3.0
type Int64MultiHook []Int64Hook
type Int8 ¶
type Int8 struct {
// contains filtered or unexported fields
}
Int8 tracks changes of bool values with a hook and Flags. See also onchg package documentation.
type Int8MultiHook ¶ added in v0.3.0
type Int8MultiHook []Int8Hook
type IntMultiHook ¶ added in v0.3.0
type IntMultiHook []IntHook
type Rune ¶
type Rune struct {
// contains filtered or unexported fields
}
Rune tracks changes of bool values with a hook and Flags. See also onchg package documentation.
type RuneMultiHook ¶ added in v0.3.0
type RuneMultiHook []RuneHook
type String ¶
type String struct {
// contains filtered or unexported fields
}
String tracks changes of bool values with a hook and Flags. See also onchg package documentation.
func NewString ¶
func NewString(init string, hook StringHook) *String
NewString creates a change-detectable String. See also section Hook Funtions.
func (*String) Reset ¶
func (cv *String) Reset(v string, hook StringHook) (string, StringHook)
Reset does not call a hook, even if the value changes. See also section Hook Funtions.
type StringHook ¶
See section Hook Funtions.
type StringMultiHook ¶ added in v0.3.0
type StringMultiHook []StringHook
type Time ¶ added in v0.2.0
type Time struct {
// contains filtered or unexported fields
}
Time tracks changes of bool values with a hook and Flags. See also onchg package documentation.
type TimeMultiHook ¶ added in v0.3.0
type TimeMultiHook []TimeHook
type Uint ¶
type Uint struct {
// contains filtered or unexported fields
}
Uint tracks changes of bool values with a hook and Flags. See also onchg package documentation.
type Uint16 ¶
type Uint16 struct {
// contains filtered or unexported fields
}
Uint16 tracks changes of bool values with a hook and Flags. See also onchg package documentation.
func NewUint16 ¶
func NewUint16(init uint16, hook Uint16Hook) *Uint16
NewUint16 creates a change-detectable Uint16. See also section Hook Funtions.
func (*Uint16) Reset ¶
func (cv *Uint16) Reset(v uint16, hook Uint16Hook) (uint16, Uint16Hook)
Reset does not call a hook, even if the value changes. See also section Hook Funtions.
type Uint16Hook ¶
See section Hook Funtions.
type Uint16MultiHook ¶ added in v0.3.0
type Uint16MultiHook []Uint16Hook
type Uint32 ¶
type Uint32 struct {
// contains filtered or unexported fields
}
Uint32 tracks changes of bool values with a hook and Flags. See also onchg package documentation.
func NewUint32 ¶
func NewUint32(init uint32, hook Uint32Hook) *Uint32
NewUint32 creates a change-detectable Uint32. See also section Hook Funtions.
func (*Uint32) Reset ¶
func (cv *Uint32) Reset(v uint32, hook Uint32Hook) (uint32, Uint32Hook)
Reset does not call a hook, even if the value changes. See also section Hook Funtions.
type Uint32Hook ¶
See section Hook Funtions.
type Uint32MultiHook ¶ added in v0.3.0
type Uint32MultiHook []Uint32Hook
type Uint64 ¶
type Uint64 struct {
// contains filtered or unexported fields
}
Uint64 tracks changes of bool values with a hook and Flags. See also onchg package documentation.
func NewUint64 ¶
func NewUint64(init uint64, hook Uint64Hook) *Uint64
NewUint64 creates a change-detectable Uint64. See also section Hook Funtions.
func (*Uint64) Reset ¶
func (cv *Uint64) Reset(v uint64, hook Uint64Hook) (uint64, Uint64Hook)
Reset does not call a hook, even if the value changes. See also section Hook Funtions.
type Uint64Hook ¶
See section Hook Funtions.
type Uint64MultiHook ¶ added in v0.3.0
type Uint64MultiHook []Uint64Hook
type Uint8 ¶
type Uint8 struct {
// contains filtered or unexported fields
}
Uint8 tracks changes of bool values with a hook and Flags. See also onchg package documentation.
type Uint8MultiHook ¶ added in v0.3.0
type Uint8MultiHook []Uint8Hook
type UintMultiHook ¶ added in v0.3.0
type UintMultiHook []UintHook
type UintPtr ¶
type UintPtr struct {
// contains filtered or unexported fields
}
UintPtr tracks changes of bool values with a hook and Flags. See also onchg package documentation.
func NewUintPtr ¶
func NewUintPtr(init uintptr, hook UintPtrHook) *UintPtr
NewUintPtr creates a change-detectable UintPtr. See also section Hook Funtions.
func (*UintPtr) Reset ¶
func (cv *UintPtr) Reset(v uintptr, hook UintPtrHook) (uintptr, UintPtrHook)
Reset does not call a hook, even if the value changes. See also section Hook Funtions.
type UintPtrHook ¶
See section Hook Funtions.
type UintPtrMultiHook ¶ added in v0.3.0
type UintPtrMultiHook []UintPtrHook