-
Notifications
You must be signed in to change notification settings - Fork 98
add options to set custom namespace separator and a method name transformer #131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
3bd8614
b51ea2b
d12cfe7
5fdbbd6
89bdd8a
7cff1cc
e1e380b
fc74ed8
9d9dbaf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| .idea/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| module github.com/filecoin-project/go-jsonrpc | ||
|
|
||
| go 1.23 | ||
| go 1.23.0 | ||
|
|
||
| require ( | ||
| github.com/google/uuid v1.1.1 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -77,7 +77,10 @@ type handler struct { | |
|
|
||
| paramDecoders map[reflect.Type]ParamDecoder | ||
|
|
||
| tracer Tracer | ||
| methodNameTransformer MethodNameTransformer | ||
|
|
||
| tracer Tracer | ||
| separator string | ||
| } | ||
|
|
||
| type Tracer func(method string, params []reflect.Value, results []reflect.Value, err error) | ||
|
|
@@ -90,9 +93,12 @@ func makeHandler(sc ServerConfig) *handler { | |
| aliasedMethods: map[string]string{}, | ||
| paramDecoders: sc.paramDecoders, | ||
|
|
||
| methodNameTransformer: sc.methodNameTransformer, | ||
|
|
||
| maxRequestSize: sc.maxRequestSize, | ||
|
|
||
| tracer: sc.tracer, | ||
| tracer: sc.tracer, | ||
| separator: sc.separator, | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -125,8 +131,11 @@ func (s *handler) register(namespace string, r interface{}) { | |
| } | ||
|
|
||
| valOut, errOut, _ := processFuncOut(funcType) | ||
| if s.methodNameTransformer != nil { | ||
| method.Name = s.methodNameTransformer(method.Name) | ||
| } | ||
|
|
||
| s.methods[namespace+"."+method.Name] = methodHandler{ | ||
| s.methods[namespace+s.separator+method.Name] = methodHandler{ | ||
|
||
| paramReceivers: recvs, | ||
| nParams: ins, | ||
|
|
||
|
|
@@ -303,7 +312,14 @@ func (s *handler) createError(err error) *JSONRPCError { | |
| return out | ||
| } | ||
|
|
||
| func (s *handler) handle(ctx context.Context, req request, w func(func(io.Writer)), rpcError rpcErrFunc, done func(keepCtx bool), chOut chanOut) { | ||
| func (s *handler) handle( | ||
raul0ligma marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ctx context.Context, | ||
| req request, | ||
| w func(func(io.Writer)), | ||
| rpcError rpcErrFunc, | ||
| done func(keepCtx bool), | ||
| chOut chanOut, | ||
| ) { | ||
| // Not sure if we need to sanitize the incoming req.Method or not. | ||
| ctx, span := s.getSpan(ctx, req) | ||
| ctx, _ = tag.New(ctx, tag.Insert(metrics.RPCMethod, req.Method)) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.