Skip to content

Commit

Permalink
refactor: Use .-seperated nested call paths to allow for purl usa…
Browse files Browse the repository at this point in the history
…ge with nested calls

Signed-off-by: Felicitas Pojtinger <felicitas@pojtinger.com>
  • Loading branch information
pojntfx committed Sep 14, 2024
1 parent 3688ac0 commit 22c8980
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
3 changes: 2 additions & 1 deletion go/cmd/purl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Usage of %v:
Examples:
%v tcp://localhost:1337/Increment '[1]'
%v tcp://localhost:1337/Time.GetSystemTime '[1]'
%v tls://localhost:443/Increment '[1]'
%v unix:///tmp/panrpc.sock/Increment '[1]'
%v unixs:///tmp/panrpc.sock/Increment '[1]'
Expand All @@ -63,7 +64,7 @@ Examples:
%v weron://examplepass:examplekey@examplecommunity/panrpc.example.webrtc/Increment '[1]'
Flags:
`, bin, bin, bin, bin, bin, bin, bin, bin, bin)
`, bin, bin, bin, bin, bin, bin, bin, bin, bin, bin)

flag.PrintDefaults()
}
Expand Down
12 changes: 8 additions & 4 deletions go/pkg/rpc/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package rpc
import (
"context"
"errors"
"path"
"reflect"
"strings"
"sync"
Expand Down Expand Up @@ -251,11 +250,16 @@ func (r Registry[R, T]) implementRemoteStructRecursively(
functionField := remote.Type().Field(i)
functionType := functionField.Type

prefix := ""
if namePrefix != "" {
prefix = "."
}

if functionType.Kind() == reflect.Struct {
if err := r.implementRemoteStructRecursively(
ctx,

path.Join(namePrefix, functionField.Name),
namePrefix+prefix+functionField.Name,

remote.FieldByName(functionField.Name),

Expand Down Expand Up @@ -298,7 +302,7 @@ func (r Registry[R, T]) implementRemoteStructRecursively(
Set(r.makeRPC(
ctx,

path.Join(namePrefix, functionField.Name),
namePrefix+prefix+functionField.Name,
functionType,
setErr,
responseResolver,
Expand Down Expand Up @@ -466,7 +470,7 @@ func (r Registry[R, T]) findLocalFunctionToCallRecursively(
}

func findMethodByFunctionCallPathRecursively(root interface{}, functionCallPath string) (reflect.Value, error) {
functionCallPathParts := strings.Split(functionCallPath, "/")
functionCallPathParts := strings.Split(functionCallPath, ".")
if len(functionCallPathParts) == 0 {
return reflect.Value{}, ErrInvalidFunctionCallPath
}
Expand Down

0 comments on commit 22c8980

Please sign in to comment.