Documentation ¶
Index ¶
- Variables
- func DestroyHandlerChain(handlerChain EventHandler)
- type ActionExecutorCreator
- type AppProfile
- type ConnectionServiceStatus
- type DiscoveryStatus
- type Event
- type EventCh
- type EventHandler
- type EventSource
- type EventType
- type Hook
- type HookAction
- type HookDefinition
- type HookManager
- type HookParameters
- func (p HookParameters) ContainsKey(key string) (ex bool)
- func (p HookParameters) ExtractInt64IfExist(key string, target *int64)
- func (p HookParameters) ExtractIntIfExist(key string, target *int)
- func (p HookParameters) ExtractStringIfExist(key string, target *string)
- func (p HookParameters) GetInt64(key string, defaultValue int64) int64
- func (p HookParameters) GetString(key string, defaultValue string) string
- type IllegalEventParamError
- type LastDialStatus
- type LogConfig
- type LogFileConfig
- type StApiError
- type SyncthingClient
- type SyncthingConfig
- type SystemStatus
- type TimeProvider
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidActionType = errors.New("invalid action type")
var ErrNotValidNativeEventType = errors.New("not a valid native event type")
Functions ¶
func DestroyHandlerChain ¶
func DestroyHandlerChain(handlerChain EventHandler)
Types ¶
type ActionExecutorCreator ¶
type ActionExecutorCreator interface {
CreateExecutor(action *HookAction, hookDef *HookDefinition) (EventHandler, error)
}
type AppProfile ¶
type AppProfile struct { Log LogConfig `koanf:"log"` Syncthing SyncthingConfig `koanf:"syncthing"` Hooks []Hook `koanf:"hooks"` }
type ConnectionServiceStatus ¶
type DiscoveryStatus ¶
type DiscoveryStatus struct {
Error *string `json:"error"`
}
type Event ¶
type EventCh ¶
type EventCh = <-chan *Event
func ConvertNativeEventChannel ¶
ConvertNativeEventChannel converts native event channel into custom event channel. The returned channel will be closed automatically once the given native event channel is closed.
Events that failed to convert to local event will be ignored.
type EventHandler ¶
type EventHandler interface { SetNext(next EventHandler) GetNext() EventHandler // Handle processes the event. It should call next handler in most cases. Handle(event *Event) // Destroy will be called when the handler will not be used anymore. // Typically, it should cancel any ongoing coroutines or release other resources. // // Do not call next handler. Destroy() }
EventHandler implements the chain of responsibility pattern, one event will be processed by different handlers one by one. The handler may terminate event propagation (e.g. filter).
func BuildEventHandlerChain ¶
func BuildEventHandlerChain(handlers ...EventHandler) EventHandler
BuildEventHandlerChain connects all given handlers into a chain, and returns the first one. If there is no handler, return nil. This function doesn't modify the tail handler.
type EventSource ¶
type EventSource interface { Subscribe(eventType EventType, params *HookParameters, hookDef *HookDefinition) (EventCh, error) // Unsubscribe must eventually close the given channel. Unsubscribe(eventCh EventCh) }
EventSource is a unified event subscription portal, including native syncthing event and extra event detected by syncthing hook.
type EventType ¶
type EventType string
const ( UnknownEventType EventType = "" ConfigSaved EventType = "st:ConfigSaved" DeviceConnected EventType = "st:DeviceConnected" DeviceDisconnected EventType = "st:DeviceDisconnected" DeviceDiscovered EventType = "st:DeviceDiscovered" DevicePaused EventType = "st:DevicePaused" DeviceResumed EventType = "st:DeviceResumed" DownloadProgress EventType = "st:DownloadProgress" Failure EventType = "st:Failure" FolderCompletion EventType = "st:FolderCompletion" FolderErrors EventType = "st:FolderErrors" FolderPaused EventType = "st:FolderPaused" FolderResumed EventType = "st:FolderResumed" FolderScanProgress EventType = "st:FolderScanProgress" FolderSummary EventType = "st:FolderSummary" FolderWatchStateChanged EventType = "st:FolderWatchStateChanged" ItemFinished EventType = "st:ItemFinished" ItemStarted EventType = "st:ItemStarted" ListenAddressesChanged EventType = "st:ListenAddressesChanged" LocalChangeDetected EventType = "st:LocalChangeDetected" LocalIndexUpdated EventType = "st:LocalIndexUpdated" LoginAttempt EventType = "st:LoginAttempt" PendingDevicesChanged EventType = "st:PendingDevicesChanged" PendingFoldersChanged EventType = "st:PendingFoldersChanged" RemoteChangeDetected EventType = "st:RemoteChangeDetected" RemoteDownloadProgress EventType = "st:RemoteDownloadProgress" RemoteIndexUpdated EventType = "st:RemoteIndexUpdated" Starting EventType = "st:Starting" StartupComplete EventType = "st:StartupComplete" StateChanged EventType = "st:StateChanged" LocalFolderContentChangeDetected EventType = "ex:LocalFolderContentChangeDetected" )
Supported event types. Each type except UnknownEventType MUST be registered in mapToStType.
func UnmarshalEventType ¶
func (EventType) ConvertToNative ¶
ConvertToNative converts current event type to syncthing native type. Returns ErrNotValidNativeEventType if failed.
func (EventType) IsNativeEvent ¶
type Hook ¶
type Hook struct { Name string `koanf:"name"` EventType string `koanf:"event-type"` Parameter HookParameters `koanf:"parameter"` Conditions []struct { Type string `koanf:"type"` Var string `koanf:"var"` Value string `koanf:"value"` } `koanf:"conditions"` Action HookAction `koanf:"action"` }
type HookAction ¶
type HookDefinition ¶
HookDefinition represents a Hook item in the configuration.
func NewHookDefinition ¶
func NewHookDefinition(name string, index int) *HookDefinition
func (*HookDefinition) AddToLogger ¶
func (d *HookDefinition) AddToLogger(logger *zap.SugaredLogger) *zap.SugaredLogger
AddToLogger adds hook definition info to the given logger, returns new logger.
type HookManager ¶
type HookManager interface { RegisterHook(hook *Hook, hookDef *HookDefinition) error UnregisterAll() }
HookManager registers hook and executes action.
type HookParameters ¶
func (HookParameters) ContainsKey ¶
func (p HookParameters) ContainsKey(key string) (ex bool)
func (HookParameters) ExtractInt64IfExist ¶
func (p HookParameters) ExtractInt64IfExist(key string, target *int64)
func (HookParameters) ExtractIntIfExist ¶
func (p HookParameters) ExtractIntIfExist(key string, target *int)
func (HookParameters) ExtractStringIfExist ¶
func (p HookParameters) ExtractStringIfExist(key string, target *string)
type IllegalEventParamError ¶
type IllegalEventParamError struct {
Message string
}
func NewIllegalEventParamError ¶
func NewIllegalEventParamError(message string) *IllegalEventParamError
func (*IllegalEventParamError) Error ¶
func (e *IllegalEventParamError) Error() string
type LastDialStatus ¶
type LogConfig ¶
type LogConfig struct { Stdout struct { Enabled bool `koanf:"enabled"` Level string `koanf:"level"` } `koanf:"stdout"` File LogFileConfig `koanf:"file"` }
type LogFileConfig ¶
type StApiError ¶
func NewStApiHttpError ¶
func NewStApiHttpError(resp *resty.Response) StApiError
func NewStApiReqError ¶
func NewStApiReqError(err error) StApiError
func (StApiError) Error ¶
func (e StApiError) Error() string
func (StApiError) Unwrap ¶
func (e StApiError) Unwrap() error
type SyncthingClient ¶
type SyncthingClient interface { GetSystemStatus() (*SystemStatus, error) // GetEvents receives events. since sets the ID of the last event you’ve already seen. The default value is 0, which // returns all events. The timeout duration can be customized with the parameter timeout(seconds). // To receive only a limited number of events, add the limit parameter with a suitable value for n and only the last n // events will be returned. // // Note: if more than one eventTypes filter is given, only subsequent events can be fetched. This function will wait // until a new event or timeout. However, if there's only one event type or empty, cached events can be fetched. // This is the intended behavior of Syncthing API, details: https://github.com/syncthing/syncthing/issues/8902 GetEvents(eventTypes []events.EventType, since int, timeout int, limit int) ([]events.Event, error) GetDiskEvents(since int, timeout int, limit int) ([]events.Event, error) SubscribeEvent(eventTypes []events.EventType, since int) <-chan events.Event UnsubscribeEvent(eventCh <-chan events.Event) }
type SyncthingConfig ¶
type SystemStatus ¶
type SystemStatus struct { Alloc int `json:"alloc"` ConnectionServiceStatus map[string]ConnectionServiceStatus `json:"connectionServiceStatus"` DiscoveryEnabled bool `json:"discoveryEnabled"` DiscoveryErrors map[string]string `json:"discoveryErrors"` DiscoveryStatus map[string]DiscoveryStatus `json:"discoveryStatus"` DiscoveryMethods int `json:"discoveryMethods"` Goroutines int `json:"goroutines"` LastDialStatus map[string]LastDialStatus `json:"lastDialStatus"` MyID string `json:"myID"` PathSeparator string `json:"pathSeparator"` StartTime time.Time `json:"startTime"` Sys int `json:"sys"` Themes []string `json:"themes"` Tilde string `json:"tilde"` Uptime int `json:"uptime"` }
type TimeProvider ¶
type TimeProvider interface {
NowUnixMilli() int64
}