mirror of
https://github.com/wavetermdev/backup.git
synced 2026-08-05 13:57:07 -07:00
set up remote connserver (#245)
This commit is contained in:
@@ -4,6 +4,8 @@
|
||||
package wshclient
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/wavetermdev/thenextwave/pkg/util/utilfn"
|
||||
"github.com/wavetermdev/thenextwave/pkg/wshrpc"
|
||||
"github.com/wavetermdev/thenextwave/pkg/wshutil"
|
||||
@@ -14,6 +16,9 @@ func sendRpcRequestCallHelper[T any](w *wshutil.WshRpc, command string, data int
|
||||
opts = &wshrpc.RpcOpts{}
|
||||
}
|
||||
var respData T
|
||||
if w == nil {
|
||||
return respData, errors.New("nil wshrpc passed to wshclient")
|
||||
}
|
||||
if opts.NoResponse {
|
||||
err := w.SendCommand(command, data, opts)
|
||||
if err != nil {
|
||||
@@ -32,17 +37,26 @@ func sendRpcRequestCallHelper[T any](w *wshutil.WshRpc, command string, data int
|
||||
return respData, nil
|
||||
}
|
||||
|
||||
func rtnErr[T any](ch chan wshrpc.RespOrErrorUnion[T], err error) {
|
||||
go func() {
|
||||
ch <- wshrpc.RespOrErrorUnion[T]{Error: err}
|
||||
close(ch)
|
||||
}()
|
||||
}
|
||||
|
||||
func sendRpcRequestResponseStreamHelper[T any](w *wshutil.WshRpc, command string, data interface{}, opts *wshrpc.RpcOpts) chan wshrpc.RespOrErrorUnion[T] {
|
||||
if opts == nil {
|
||||
opts = &wshrpc.RpcOpts{}
|
||||
}
|
||||
respChan := make(chan wshrpc.RespOrErrorUnion[T])
|
||||
if w == nil {
|
||||
rtnErr(respChan, errors.New("nil wshrpc passed to wshclient"))
|
||||
return respChan
|
||||
}
|
||||
reqHandler, err := w.SendComplexRequest(command, data, opts)
|
||||
if err != nil {
|
||||
go func() {
|
||||
respChan <- wshrpc.RespOrErrorUnion[T]{Error: err}
|
||||
close(respChan)
|
||||
}()
|
||||
rtnErr(respChan, err)
|
||||
return respChan
|
||||
} else {
|
||||
go func() {
|
||||
defer close(respChan)
|
||||
|
||||
@@ -107,6 +107,7 @@ type RpcOpts struct {
|
||||
type RpcContext struct {
|
||||
BlockId string `json:"blockid,omitempty"`
|
||||
TabId string `json:"tabid,omitempty"`
|
||||
Conn string `json:"conn,omitempty"`
|
||||
}
|
||||
|
||||
func HackRpcContextIntoData(dataPtr any, rpcContext RpcContext) {
|
||||
|
||||
Reference in New Issue
Block a user