Documentation
¶
Index ¶
- Variables
- func ProxyStorage(s Storage, vm *goja.Runtime) goja.Proxy
- func WrapPacketBuilder(p *liter.PacketBuilder, conn *liter.Conn, vm *goja.Runtime, ...) (o *goja.Object)
- type Event
- type EventEmitter
- type Exportsable
- type JsonStorage
- type Manager
- func (m *Manager) Emit(event *Event) (done <-chan bool)
- func (m *Manager) List() (scripts []*Script)
- func (m *Manager) Load(path string) (script *Script, err error)
- func (m *Manager) LoadFromDir(path string) (scripts []*Script, err error)
- func (m *Manager) LoadWithContext(ctx context.Context, path string) (script *Script, err error)
- func (m *Manager) SetLogger(loger logger.Logger)
- func (m *Manager) Unload(id string) (script *Script)
- func (m *Manager) UnloadAll() (scripts []*Script)
- func (m *Manager) WrapConn(conn *liter.Conn) (wrapped *WrappedConn)
- type MemoryStorage
- func (s *MemoryStorage) Clear()
- func (s *MemoryStorage) Exports() *goja.Object
- func (s *MemoryStorage) GetItem(key string) (value goja.Value)
- func (s *MemoryStorage) Keys() (keys []string)
- func (s *MemoryStorage) Len() int
- func (s *MemoryStorage) RemoveItem(key string)
- func (s *MemoryStorage) SetItem(key string, value goja.Value)
- type PluginIdLoadedError
- type PluginLoadError
- type Script
- type ScriptMeta
- type Storage
- type WrappedConn
- type WrappedPacketReader
Constants ¶
This section is empty.
Variables ¶
Functions ¶
Types ¶
type Event ¶
type Event struct { Name string Data map[string]any Cancelable bool // contains filtered or unexported fields }
type EventEmitter ¶
type EventEmitter struct {
// contains filtered or unexported fields
}
func NewEventEmitter ¶
func NewEventEmitter(vm *goja.Runtime, loop *eventloop.EventLoop) (e *EventEmitter)
func (*EventEmitter) EmitAsync ¶
func (e *EventEmitter) EmitAsync(event *Event) (done <-chan bool)
func (*EventEmitter) ExportTo ¶
func (e *EventEmitter) ExportTo(o *goja.Object)
type Exportsable ¶
type JsonStorage ¶
type JsonStorage struct {
// contains filtered or unexported fields
}
TODO JsonStorage is a local storage, it's thready-safe
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
func NewManager ¶
func NewManager() (m *Manager)
func (*Manager) LoadFromDir ¶
LoadFromDir will load all plugins under the path which have the ext `.zip`, and return all successfully loaded plugins with a possible error If the target path is not exists, LoadFromDir will do nothing and return without error If there are errors during load any plugin, the errors will be wrapped use `errors.Join`, and other plugins will continue to be load.
func (*Manager) LoadWithContext ¶
LoadWithContext will load a plugin packet use the given filepath. The first capture group will be the script's ID. The second capture group is the script's version If the script's ID is already loaded, then an error will be returned
func (*Manager) Unload ¶
Unload will unload plugin by ID and return the unloaded plugin instance During unloading, the unload event will be emitted
func (*Manager) UnloadAll ¶
UnloadAll will unload all plugins and return them During unloading, the unload event will be emitted
func (*Manager) WrapConn ¶
func (m *Manager) WrapConn(conn *liter.Conn) (wrapped *WrappedConn)
type MemoryStorage ¶
type MemoryStorage struct {
// contains filtered or unexported fields
}
MemoryStorage is designed for single thread use, so it's not thread-safe. It should only be called inside the js loop with same Runtime instance.
func NewMemoryStorage ¶
func NewMemoryStorage(vm *goja.Runtime) (s *MemoryStorage)
func (*MemoryStorage) Clear ¶
func (s *MemoryStorage) Clear()
func (*MemoryStorage) Exports ¶
func (s *MemoryStorage) Exports() *goja.Object
func (*MemoryStorage) Keys ¶
func (s *MemoryStorage) Keys() (keys []string)
func (*MemoryStorage) Len ¶
func (s *MemoryStorage) Len() int
func (*MemoryStorage) RemoveItem ¶
func (s *MemoryStorage) RemoveItem(key string)
type PluginIdLoadedError ¶ added in v0.3.0
type PluginIdLoadedError struct {
Id string
}
func (*PluginIdLoadedError) Error ¶ added in v0.3.0
func (e *PluginIdLoadedError) Error() string
type PluginLoadError ¶ added in v0.3.0
func (*PluginLoadError) Error ¶ added in v0.3.0
func (e *PluginLoadError) Error() string
func (*PluginLoadError) Unwrap ¶ added in v0.3.0
func (e *PluginLoadError) Unwrap() error
type Script ¶
type Script struct { ScriptMeta // contains filtered or unexported fields }
type ScriptMeta ¶ added in v0.3.0
type WrappedConn ¶
type WrappedConn struct { *liter.Conn OnClose func() // contains filtered or unexported fields }
func WrapConn ¶
func WrapConn(conn *liter.Conn, vm *goja.Runtime, loop *eventloop.EventLoop) (c *WrappedConn)
func (*WrappedConn) Close ¶ added in v0.2.6
func (c *WrappedConn) Close() (err error)
func (*WrappedConn) Closed ¶
func (c *WrappedConn) Closed() bool
Closed return whether the connection is or not closed manually
func (*WrappedConn) Emit ¶
func (c *WrappedConn) Emit(event *Event) (done <-chan bool)
func (*WrappedConn) Exports ¶
func (c *WrappedConn) Exports() *goja.Object
func (*WrappedConn) Recv ¶
func (c *WrappedConn) Recv() (w *WrappedPacketReader, err error)
type WrappedPacketReader ¶
type WrappedPacketReader struct { *liter.PacketReader // contains filtered or unexported fields }
func WrapPacketReader ¶
func WrapPacketReader(p *liter.PacketReader, vm *goja.Runtime) *WrappedPacketReader
func (*WrappedPacketReader) Exports ¶
func (p *WrappedPacketReader) Exports() *goja.Object