monitor

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 28, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GuardOption

type GuardOption func(*SessionGuard)

GuardOption configures a SessionGuard.

func WithPauseDuration

func WithPauseDuration(d time.Duration) GuardOption

WithPauseDuration sets the pause duration after a session expiration.

type Handler

type Handler func(ctx context.Context, msg types.WeixinMessage)

Handler is called for each incoming message.

type Monitor

type Monitor struct {
	// contains filtered or unexported fields
}

Monitor long-polls for new messages and dispatches them to a handler.

func NewMonitor

func NewMonitor(c *client.Client, handler Handler, opts ...MonitorOption) *Monitor

NewMonitor creates a Monitor for the given client and handler.

func (*Monitor) Run

func (m *Monitor) Run(ctx context.Context) error

Run starts the long-poll loop. Blocks until ctx is canceled.

type MonitorOption

type MonitorOption func(*Monitor)

MonitorOption configures a Monitor.

func WithSessionGuard

func WithSessionGuard(g *SessionGuard) MonitorOption

WithSessionGuard sets the session guard for pause-on-expiry behavior.

func WithSyncState

func WithSyncState(s SyncState) MonitorOption

WithSyncState sets the sync state persistence backend.

type SessionGuard

type SessionGuard struct {
	// contains filtered or unexported fields
}

SessionGuard prevents API calls for a configurable duration after a session expiration is detected.

func NewSessionGuard

func NewSessionGuard(opts ...GuardOption) *SessionGuard

NewSessionGuard creates a SessionGuard with a default pause duration of 1 hour.

func (*SessionGuard) Check

func (g *SessionGuard) Check() error

Check returns an error if the guard is currently paused, or nil if API calls are allowed.

func (*SessionGuard) IsPaused

func (g *SessionGuard) IsPaused() bool

IsPaused reports whether the guard is currently paused.

func (*SessionGuard) RemainingPause

func (g *SessionGuard) RemainingPause() time.Duration

RemainingPause returns the remaining pause duration. Returns 0 if not paused.

func (*SessionGuard) Trigger

func (g *SessionGuard) Trigger()

Trigger activates the pause, setting pauseUntil to now + pauseDuration.

type SyncState

type SyncState interface {
	Load() (string, error)
	Save(buf string) error
}

SyncState persists the long-poll sync buffer between restarts.

func NewFileSyncState

func NewFileSyncState(path string) SyncState

NewFileSyncState returns a SyncState that persists to a JSON file.

func NewMemorySyncState

func NewMemorySyncState() SyncState

NewMemorySyncState returns an in-memory SyncState with no persistence.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL