Documentation
¶
Index ¶
- Constants
- Variables
- func FormatError(code string, err error, context string) error
- func IsConnectionError(err error) bool
- func IsInvalidInput(err error) bool
- func IsNotFound(err error) bool
- type ConfigChangeEvent
- type ConfigChangeHandler
- type ConfigService
- type ConfigStructBinding
- type ConfigValue
- type Option
- type ServiceOptions
Constants ¶
View Source
const ( Created = "created" Updated = "updated" Deleted = "deleted" )
View Source
const ( // Error code prefixes ErrCodeNotFound = "CFG-404" // Not found errors ErrCodeInvalidInput = "CFG-400" // Invalid input errors ErrCodeInternal = "CFG-500" // Internal service errors ErrCodeConnection = "CFG-503" // Connection-related errors ErrCodePermission = "CFG-403" // Permission denied errors )
Error codes for better categorization of errors
Variables ¶
View Source
var ( // ErrNotFound indicates that the requested configuration was not found ErrNotFound = errors.New("configuration not found") // ErrInvalidPath indicates that the provided path is invalid ErrInvalidPath = errors.New("invalid configuration path") // ErrInvalidValue indicates that the provided value is invalid ErrInvalidValue = errors.New("invalid configuration value") // ErrNodeHasChildren indicates that the node cannot be deleted because it has children ErrNodeHasChildren = errors.New("cannot delete node with children") // ErrInvalidStructPtr indicates that the provided struct pointer is invalid ErrInvalidStructPtr = errors.New("invalid struct pointer") // ErrNilHandler indicates that a nil handler was provided ErrNilHandler = errors.New("handler cannot be nil") // ErrSubscriptionNotFound indicates that the subscription ID was not found ErrSubscriptionNotFound = errors.New("subscription not found") // ErrConnectionFailed indicates that the connection to ZooKeeper failed ErrConnectionFailed = errors.New("failed to connect to ZooKeeper") )
Functions ¶
func FormatError ¶
FormatError creates a standardized error message with a code prefix
func IsConnectionError ¶
IsConnectionError checks if an error is a connection error
func IsInvalidInput ¶
IsInvalidInput checks if an error is an invalid input error
func IsNotFound ¶
IsNotFound checks if an error is a not found error
Types ¶
type ConfigChangeEvent ¶
type ConfigChangeEvent struct {
Path string `json:"path"`
OldValue ConfigValue `json:"old_value,omitempty"`
NewValue ConfigValue `json:"new_value,omitempty"`
ChangeType string `json:"change_type"`
Timestamp time.Time `json:"timestamp"`
}
type ConfigChangeHandler ¶
type ConfigChangeHandler func(event ConfigChangeEvent)
type ConfigService ¶
type ConfigService interface {
Get(ctx context.Context, path string, watch ...bool) (ConfigValue, error)
Set(ctx context.Context, path string, value any, watch ...bool) error
Delete(ctx context.Context, path string) error
Exists(ctx context.Context, path string) (bool, error)
List(ctx context.Context, path string) ([]string, error)
Subscribe(ctx context.Context, path string, handler ConfigChangeHandler) (string, error)
Unsubscribe(subscriptionID string) error
GetEffective(ctx context.Context, path string) (ConfigValue, error)
SetBatch(ctx context.Context, configs map[string]any, watch ...bool) error
GetBatch(ctx context.Context, paths []string, watch ...bool) (map[string]ConfigValue, error)
Export(ctx context.Context, rootPath string) (map[string]ConfigValue, error)
Import(ctx context.Context, configs map[string]ConfigValue, watch ...bool) error
BindStructWithCallback(ctx context.Context, path string, structPtr any, callback func(any)) (*ConfigStructBinding, error)
UnbindStruct(binding *ConfigStructBinding) error
ReloadStruct(ctx context.Context, binding *ConfigStructBinding) error
SetFromStruct(ctx context.Context, path string, structPtr any) error
Close() error
}
func NewConfigService ¶
func NewConfigService(zkServers []string, opts ...Option) (ConfigService, error)
NewConfigService creates a new configuration service
type ConfigStructBinding ¶
type ConfigValue ¶
type Option ¶
type Option func(*ServiceOptions)
Option is a function type for applying options to ServiceOptions
func WithBasePath ¶
WithBasePath sets the base path in ZooKeeper
func WithDelimiter ¶
WithDelimiter sets the delimiter for hierarchical keys
type ServiceOptions ¶
type ServiceOptions struct {
BasePath string // Base path in ZooKeeper
Delimiter string // Delimiter used for hierarchical keys
Environment string // Environment (e.g., "dev", "prod")
Namespace string // Namespace (e.g., "ecommerce")
}
ServiceOptions contains configuration options for the config service
Click to show internal directories.
Click to hide internal directories.