Documentation
¶
Index ¶
- Constants
- func RegisterDriver(scheme string, driver Driver)
- type Driver
- type Ex
- func (w Ex) Close()
- func (w Ex) SetUpdateCallback(callback func(string)) error
- func (w *Ex) Update() error
- func (w *Ex) UpdateForAddPolicies(sec string, ptype string, rules ...[]string) error
- func (w *Ex) UpdateForAddPolicy(sec, ptype string, params ...string) error
- func (w *Ex) UpdateForRemoveFilteredPolicy(sec, ptype string, fieldIndex int, fieldValues ...string) error
- func (w *Ex) UpdateForRemovePolicies(sec string, ptype string, rules ...[]string) error
- func (w *Ex) UpdateForRemovePolicy(sec, ptype string, params ...string) error
- func (w *Ex) UpdateForSavePolicy(_ model.Model) error
- type MarshalUnmarshaler
- type Option
- type PubSub
- type UpdateMessage
- type Watcher
Constants ¶
const ( UpdateTypePolicyChanged = "policy-changed" UpdateTypeAddPolicy = "add-policy" UpdateTypeRemovePolicy = "remove-policy" UpdateTypeRemoveFilteredPolicy = "remove-filtered-policy" UpdateTypeSavePolicy = "save-policy" UpdateTypeAddPolicies = "add-policies" UpdateTypeRemovePolicies = "remove-policies" )
Update types for Ex messages.
const DefaultTopic = "casbin-policy-updates"
DefaultTopic is the default topic used for policy update notifications.
Variables ¶
This section is empty.
Functions ¶
func RegisterDriver ¶
RegisterDriver registers a driver for the given scheme (e.g., "redis", "kafka"). This allows casbin-watcher to dynamically find and create PubSub instances.
Types ¶
type Driver ¶
type Driver interface {
// NewPubSub creates a new PubSub instance from the parsed URL and logger.
// The driver is responsible for parsing and validating its specific configuration
// from the URL's host, path, and query parameters.
NewPubSub(ctx context.Context, parsedURL *url.URL, logger watermill.LoggerAdapter) (PubSub, error)
}
Driver is the interface for creating a PubSub instance for a specific backend. Each driver is responsible for parsing its specific configuration from the URL.
type Ex ¶
type Ex struct {
// contains filtered or unexported fields
}
Ex implements persist.WatcherEx.
func NewWatcherEx ¶
NewWatcherEx creates a new Ex (extended mode).
func (Ex) Close ¶
func (w Ex) Close()
Close stops and releases the watcher. Public interface method - errors are logged but not returned to match persist.Watcher interface.
func (Ex) SetUpdateCallback ¶
func (*Ex) Update ¶
Update calls the update callback of other instances to synchronize their policy. This method is part of the Watcher interface and publishes a generic "policy-changed" message.
func (*Ex) UpdateForAddPolicies ¶
func (*Ex) UpdateForAddPolicy ¶
func (*Ex) UpdateForRemoveFilteredPolicy ¶
func (*Ex) UpdateForRemovePolicies ¶
func (*Ex) UpdateForRemovePolicy ¶
type MarshalUnmarshaler ¶
type MarshalUnmarshaler interface {
Marshal(v interface{}) ([]byte, error)
Unmarshal(data []byte, v interface{}) error
}
MarshalUnmarshaler is the interface for serializing and deserializing UpdateMessage.
func DefaultCodec ¶
func DefaultCodec() MarshalUnmarshaler
DefaultCodec returns the default gob codec.
type Option ¶
type Option func(*options)
Option is a functional option for configuring the Watcher.
func WithCodec ¶
func WithCodec(codec MarshalUnmarshaler) Option
WithCodec sets the custom MarshalUnmarshaler for UpdateMessage.
func WithLogger ¶
func WithLogger(logger watermill.LoggerAdapter) Option
WithLogger sets the Watermill logger adapter to use.
type PubSub ¶
type PubSub interface {
message.Publisher
message.Subscriber
}
PubSub is a high-level interface that combines Publisher and Subscriber. This is the standard interface that all drivers must produce.
type UpdateMessage ¶
UpdateMessage represents the payload for Ex updates.
type Watcher ¶
type Watcher struct {
// contains filtered or unexported fields
}
Watcher implements persist.Watcher.
func NewWatcher ¶
NewWatcher creates a new Watcher (basic mode).
func (Watcher) Close ¶
func (w Watcher) Close()
Close stops and releases the watcher. Public interface method - errors are logged but not returned to match persist.Watcher interface.