set up remote connserver (#245)

This commit is contained in:
Mike Sawka
2024-08-18 21:26:44 -07:00
committed by GitHub
parent c30188552f
commit 85874f92ca
21 changed files with 357 additions and 212 deletions
+18 -4
View File
@@ -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)
+1
View File
@@ -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) {