Documentation
¶
Index ¶
- func SetDefaults[T any](data *T)
- type C
- func (cog *C[T]) AddCallback(f Callback[T]) int
- func (cog *C[T]) AddSubscriber(f Subscriber[T]) int
- func (cog *C[T]) Config() T
- func (cog *C[T]) GetTimestamp() string
- func (cog *C[T]) RemoveCallback(id int) error
- func (cog *C[T]) RemoveSubscriber(id int) error
- func (cog *C[T]) String(masks ...MaskFn[T]) (string, error)
- func (cog *C[T]) Update(new T) error
- type Callback
- type ConfigHandler
- type MaskFn
- type Subscriber
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetDefaults ¶ added in v1.7.0
func SetDefaults[T any](data *T)
Types ¶
type C ¶ added in v1.7.0
type C[T any] struct { // contains filtered or unexported fields }
func Init ¶
func Init[T any](handler ...ConfigHandler) (*C[T], error)
Initialize library. Returns cog instance. Receives config handler. To use default builtin JSON file handler: c, err := cog.Init[ConfigStruct](handler.New())
func (*C[T]) AddCallback ¶ added in v1.7.0
Register new callback function. It will be called after config update in non blocking goroutine. This method returns callback id (int). It can be used to remove callback by calling cog.RemoveCallback(id).
func (*C[T]) AddSubscriber ¶ added in v1.7.0
func (cog *C[T]) AddSubscriber(f Subscriber[T]) int
Register new subscriber function. It will be called after config update and wait for every subscriber to be updated. If at least one subscriber returns an error, update stops and rollback is initiated for all updated subscribers. This method returns subscriber id (int). It can be used to remove subscriber by calling cog.RemoveSubscriber(id).
func (*C[T]) GetTimestamp ¶ added in v1.7.0
Get timestamp of the configuration. It reflects when configuration has been updated or loaded last time.
func (*C[T]) RemoveCallback ¶ added in v1.7.0
Remove callback by id.
func (*C[T]) RemoveSubscriber ¶ added in v1.7.0
Remove subscriber by id.