Initial commit, pt. 39

This commit is contained in:
Dmitrii Okunev
2024-07-07 21:43:01 +01:00
parent 3cb9359362
commit 708d156d96
9 changed files with 312 additions and 23 deletions

View File

@@ -22,6 +22,7 @@ import (
"github.com/xaionaro-go/streamctl/pkg/streamd/api"
"github.com/xaionaro-go/streamctl/pkg/streamd/config"
"github.com/xaionaro-go/streamctl/pkg/streamd/grpc/go/streamd_grpc"
"github.com/xaionaro-go/streamctl/pkg/streampanel/consts"
)
type GRPCServer struct {
@@ -474,3 +475,31 @@ func (grpc *GRPCServer) SubscribeToOAuthRequests(
func (grpc *GRPCServer) OpenOAuthURL(authURL string) {
grpc.OAuthURLBroadcaster.Submit(authURL)
}
func (grpc *GRPCServer) GetVariable(
ctx context.Context,
req *streamd_grpc.GetVariableRequest,
) (*streamd_grpc.GetVariableReply, error) {
key := consts.VarKey(req.GetKey())
b, err := grpc.StreamD.GetVariable(ctx, key)
if err != nil {
return nil, fmt.Errorf("unable to get variable '%s': %w", key, err)
}
return &streamd_grpc.GetVariableReply{
Key: string(key),
Value: b,
}, nil
}
func (grpc *GRPCServer) SetVariable(
ctx context.Context,
req *streamd_grpc.SetVariableRequest,
) (*streamd_grpc.SetVariableReply, error) {
key := consts.VarKey(req.GetKey())
err := grpc.StreamD.SetVariable(ctx, key, req.GetValue())
if err != nil {
return nil, fmt.Errorf("unable to set variable '%s': %w", key, err)
}
return &streamd_grpc.SetVariableReply{}, nil
}