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
- func (e *EventEmitter) Emit(event *Event) (cancelled bool)
- func (e *EventEmitter) EmitAsync(event *Event) (done <-chan bool)
- func (e *EventEmitter) EventNames() (names []string)
- func (e *EventEmitter) ExportTo(o *goja.Object)
- func (e *EventEmitter) Listeners(name string) (handlers []goja.Callable)
- func (e *EventEmitter) Off(name string, listener goja.Callable)
- func (e *EventEmitter) OffAsync(name string, listener goja.Callable)
- func (e *EventEmitter) On(name string, listener goja.Callable) *EventEmitter
- func (e *EventEmitter) OnAsync(name string, listener goja.Callable)
- func (e *EventEmitter) RemoveAllListeners(name string)
- 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 Script
- 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) Emit ¶
func (e *EventEmitter) Emit(event *Event) (cancelled bool)
func (*EventEmitter) EmitAsync ¶
func (e *EventEmitter) EmitAsync(event *Event) (done <-chan bool)
func (*EventEmitter) EventNames ¶
func (e *EventEmitter) EventNames() (names []string)
func (*EventEmitter) ExportTo ¶
func (e *EventEmitter) ExportTo(o *goja.Object)
func (*EventEmitter) Listeners ¶
func (e *EventEmitter) Listeners(name string) (handlers []goja.Callable)
func (*EventEmitter) OffAsync ¶
func (e *EventEmitter) OffAsync(name string, listener goja.Callable)
func (*EventEmitter) On ¶
func (e *EventEmitter) On(name string, listener goja.Callable) *EventEmitter
func (*EventEmitter) RemoveAllListeners ¶
func (e *EventEmitter) RemoveAllListeners(name string)
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 `.js`, and return all successfully loaded plugins with a possible error If the target path is not exists, LoadFromDir will do nothing and return no 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 script plugin use the given filepath. Script's filename must match `^([a-z_][0-9a-z_]{0,31})(?:@(\d+(?:\.\d+)*)(?:-.+)?)?\..+$` 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 Script ¶
type Script struct {
// contains filtered or unexported fields
}
type WrappedConn ¶
type WrappedConn struct { *liter.Conn // contains filtered or unexported fields }
func WrapConn ¶
func WrapConn(conn *liter.Conn, vm *goja.Runtime, loop *eventloop.EventLoop) (c *WrappedConn)
func (*WrappedConn) Closed ¶
func (c *WrappedConn) Closed() bool
Closed return wheather the connection is closed by the script
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