Documentation
¶
Index ¶
- Variables
- type BasFunction
- type BasRemoteClient
- func (c *BasRemoteClient) Close() error
- func (c *BasRemoteClient) CreateThread() *BasThread
- func (c *BasRemoteClient) IsStarted() bool
- func (c *BasRemoteClient) RunFunction(name string, params map[string]interface{}) (*BasFunction, error)
- func (c *BasRemoteClient) Send(type_ string, data map[string]interface{}, async_ bool) (int, error)
- func (c *BasRemoteClient) SendAsync(type_ string, data map[string]interface{}) (json.RawMessage, error)
- func (c *BasRemoteClient) Start(timeout time.Duration) error
- func (c *BasRemoteClient) StartThread(threadID int) error
- func (c *BasRemoteClient) StopThread(threadID int) error
- type BasThread
- type FunctionError
- type Message
- type Options
- type Response
- type Script
Constants ¶
This section is empty.
Variables ¶
var ( ErrSocketNotConnected = errors.New("cannot connect to the WebSocket server") ErrScriptNotSupported = errors.New("script engine not supported (required 22.4.2 or newer)") ErrClientNotStarted = errors.New("request can not be sent: client is not started") ErrScriptNotExist = errors.New("script with selected name does not exist") ErrAuthentication = errors.New("unsuccessful authentication") ErrAlreadyRunning = errors.New("another task is already running, unable to start a new one") )
Functions ¶
This section is empty.
Types ¶
type BasFunction ¶
type BasFunction struct {
// contains filtered or unexported fields
}
BasFunction represents a one-shot BAS function call. It starts a new thread, runs the function, then stops the thread.
func (*BasFunction) Result ¶
func (r *BasFunction) Result() <-chan runResult
Result returns the channel that delivers exactly one runResult when the task finishes.
func (*BasFunction) Stop ¶
func (f *BasFunction) Stop() error
Stop immediately stops the function's thread.
type BasRemoteClient ¶
type BasRemoteClient struct {
Options *Options
// contains filtered or unexported fields
}
BasRemoteClient provides methods for remotely controlling a BAS engine.
func New ¶
func New(opts *Options) (*BasRemoteClient, error)
New creates a new BasRemoteClient. Call Start() to connect.
func (*BasRemoteClient) Close ¶
func (c *BasRemoteClient) Close() error
Close shuts down the WebSocket connection and kills the engine process.
func (*BasRemoteClient) CreateThread ¶
func (c *BasRemoteClient) CreateThread() *BasThread
CreateThread creates a new reusable BAS thread object.
func (*BasRemoteClient) IsStarted ¶
func (c *BasRemoteClient) IsStarted() bool
IsStarted reports whether the client has completed initialisation.
func (*BasRemoteClient) RunFunction ¶
func (c *BasRemoteClient) RunFunction(name string, params map[string]interface{}) (*BasFunction, error)
RunFunction starts a one-shot BAS function call in a new thread.
func (*BasRemoteClient) SendAsync ¶
func (c *BasRemoteClient) SendAsync(type_ string, data map[string]interface{}) (json.RawMessage, error)
SendAsync sends a message and blocks until the response arrives.
func (*BasRemoteClient) Start ¶
func (c *BasRemoteClient) Start(timeout time.Duration) error
Start initialises the engine, connects the WebSocket and waits for the BAS thread_start handshake. timeout ≤ 0 means no timeout.
func (*BasRemoteClient) StartThread ¶
func (c *BasRemoteClient) StartThread(threadID int) error
StartThread sends a start_thread command for the given thread ID.
func (*BasRemoteClient) StopThread ¶
func (c *BasRemoteClient) StopThread(threadID int) error
StopThread sends a stop_thread command for the given thread ID.
type BasThread ¶
type BasThread struct {
// contains filtered or unexported fields
}
BasThread is a reusable BAS thread. Unlike BasFunction it does not automatically stop after the first function call.
func (*BasThread) IsRunning ¶
IsRunning reports whether the thread is currently executing a function.
func (*BasThread) Result ¶
func (r *BasThread) Result() <-chan runResult
Result returns the channel that delivers exactly one runResult when the task finishes.
func (*BasThread) RunFunction ¶
RunFunction queues a BAS function on this thread and returns self for chaining. Returns ErrAlreadyRunning if a function is already executing on this thread.
type FunctionError ¶
type FunctionError struct {
Msg string
}
FunctionError is returned when BAS reports a function-level failure.
func (*FunctionError) Error ¶
func (e *FunctionError) Error() string
type Message ¶
type Message struct {
Async bool `json:"async"`
Type string `json:"type"`
ID int `json:"id"`
Data json.RawMessage `json:"data,omitempty"`
}
Message represents a single BAS WebSocket protocol message.
func MessageFromJSON ¶
MessageFromJSON deserialises a JSON string into a Message.
func (Message) DataString ¶
DataString returns the raw Data field as a plain string (stripping JSON quotes if it is a JSON string literal).
type Options ¶
type Options struct {
// WorkingDir is the directory used to store downloaded engine files.
// Defaults to <cwd>/data.
WorkingDir string
// ScriptName is the name of the private BAS script to connect to.
ScriptName string
// Login is the BAS account login with access to the script.
Login string
// Password is the BAS account password.
Password string
}
Options holds client configuration.
type Response ¶
type Response struct {
Success bool `json:"Success"`
Message string `json:"Message"`
Result json.RawMessage `json:"Result"`
}
Response is the payload returned by BAS for async task requests.
func ParseResponse ¶
ParseResponse deserialises a JSON string into a Response.
type Script ¶
type Script struct {
// contains filtered or unexported fields
}
Script holds metadata returned by the BAS script-properties API.
func (*Script) EngineVersion ¶
EngineVersion returns the engine version string required by this script.
func (*Script) IsSupported ¶
IsSupported reports whether the engine version meets the minimum requirement (22.4.2+).