Documentation
¶
Index ¶
- type Event
- type HandlerFunc
- type Request
- type Response
- type Router
- func (r *Router) Handle(method string, handler HandlerFunc)
- func (r *Router) HandleCustom(name string, handler HandlerFunc)
- func (r *Router) HandleMessage(rawMsg string) string
- func (r *Router) OnShutdown(fn func())
- func (r *Router) RunShutdownHooks()
- func (r *Router) SendEvent(eventName string, data any)
- func (r *Router) SetEvalFunc(fn func(js string))
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HandlerFunc ¶
type HandlerFunc func(params json.RawMessage) (any, error)
HandlerFunc processes an IPC request and returns a result or error.
type Request ¶
type Request struct {
ID string `json:"id"`
Method string `json:"method"`
Params json.RawMessage `json:"params"`
}
Request is a message from JS to Go.
type Response ¶
type Response struct {
ID string `json:"id"`
Result any `json:"result"`
Error string `json:"error,omitempty"`
}
Response is a message from Go to JS.
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router routes IPC method calls to handler functions.
func SetupRouter ¶
func SetupRouter() *Router
SetupRouter creates and returns a router with no handlers registered. API handlers are registered by calling router.Handle() from each api package.
func (*Router) Handle ¶
func (r *Router) Handle(method string, handler HandlerFunc)
Handle registers a handler for a method name.
func (*Router) HandleCustom ¶ added in v0.2.1
func (r *Router) HandleCustom(name string, handler HandlerFunc)
HandleCustom registers a custom handler invokable from JS via lightshell.invoke(name, payload).
func (*Router) HandleMessage ¶
HandleMessage processes a raw JSON message from the webview and returns the JSON response.
func (*Router) OnShutdown ¶ added in v0.2.1
func (r *Router) OnShutdown(fn func())
OnShutdown registers a function to be called when the app is shutting down.
func (*Router) RunShutdownHooks ¶ added in v0.2.1
func (r *Router) RunShutdownHooks()
RunShutdownHooks calls all registered shutdown hooks.
func (*Router) SetEvalFunc ¶
SetEvalFunc sets the function used to send JS to the webview.