Documentation
¶
Index ¶
- func SetDefaults[T any](data *T)
- type C
- func (c *C[T]) AddCallback(f Callback[T]) int
- func (c *C[T]) AddSubscriber(f Subscriber[T]) int
- func (c *C[T]) Config() T
- func (c *C[T]) GetTimestamp() time.Time
- func (c *C[T]) RemoveCallback(id int) error
- func (c *C[T]) RemoveSubscriber(id int) error
- func (c *C[T]) String(masks ...MaskFn[T]) (string, error)
- func (c *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 ¶
func SetDefaults[T any](data *T)
SetDefaults fills zero-value fields in data using struct tags ("default" for literal values, "env" for environment variables).
Types ¶
type C ¶
type C[T any] struct { // contains filtered or unexported fields }
func Init ¶
func Init[T any](handler ...ConfigHandler) (*C[T], error)
Init initializes the library and returns a cog instance. An optional ConfigHandler can be provided; if omitted, a default built-in file handler is used (JSON with dynamic type detection).
func (*C[T]) AddCallback ¶
AddCallback registers a function that is called asynchronously (in a goroutine) after every successful config update. Returns an ID that can be used with RemoveCallback.
func (*C[T]) AddSubscriber ¶
func (c *C[T]) AddSubscriber(f Subscriber[T]) int
AddSubscriber registers a function that is called synchronously on config update. If any subscriber returns an error, the update is rolled back. Returns an ID that can be used with RemoveSubscriber.
func (*C[T]) GetTimestamp ¶
GetTimestamp returns the time of the last configuration load or update.
func (*C[T]) RemoveCallback ¶
RemoveCallback removes a previously registered callback by ID.
func (*C[T]) RemoveSubscriber ¶
RemoveSubscriber removes a previously registered subscriber by ID.
type Subscriber ¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
defaults
command
|
|
|
rollback
command
|
|
|
subscriber
command
|
|
|
update
command
|
|
|
validation
command
|
|