Skip to content

Commit 89bdd8a

Browse files
committed
ft: better naming
1 parent 5fdbbd6 commit 89bdd8a

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,11 +269,11 @@ func main() {
269269
}
270270
```
271271

272-
### Using `WithMethodTransformer`
272+
### Using `WithMethodNameTransformer`
273273
```go
274274
func main() {
275275
// create a new server instance with a custom method transformer
276-
rpcServer := jsonrpc.NewServer(jsonrpc.WithMethodTransformer(strcase.ToSnake))
276+
rpcServer := jsonrpc.NewServer(jsonrpc.WithMethodNameTransformer(toSnakeCase))
277277

278278
// create a handler instance and register it
279279
serverHandler := &SimpleServerHandler{}

handler.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ type handler struct {
7777

7878
paramDecoders map[reflect.Type]ParamDecoder
7979

80-
methodTransformer MethodTransformer
80+
methodNameTransformer MethodNameTransformer
8181

8282
tracer Tracer
8383
separator string
@@ -93,7 +93,7 @@ func makeHandler(sc ServerConfig) *handler {
9393
aliasedMethods: map[string]string{},
9494
paramDecoders: sc.paramDecoders,
9595

96-
methodTransformer: sc.methodTransformer,
96+
methodNameTransformer: sc.methodNameTransformer,
9797

9898
maxRequestSize: sc.maxRequestSize,
9999

@@ -131,8 +131,8 @@ func (s *handler) register(namespace string, r interface{}) {
131131
}
132132

133133
valOut, errOut, _ := processFuncOut(funcType)
134-
if s.methodTransformer != nil {
135-
method.Name = s.methodTransformer(method.Name)
134+
if s.methodNameTransformer != nil {
135+
method.Name = s.methodNameTransformer(method.Name)
136136
}
137137

138138
s.methods[namespace+s.separator+method.Name] = methodHandler{

options_server.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type jsonrpcReverseClient struct{ reflect.Type }
1313

1414
type ParamDecoder func(ctx context.Context, json []byte) (reflect.Value, error)
1515

16-
type MethodTransformer func(string) string
16+
type MethodNameTransformer func(string) string
1717

1818
const defaultSeparator = "."
1919

@@ -24,10 +24,10 @@ type ServerConfig struct {
2424
paramDecoders map[reflect.Type]ParamDecoder
2525
errors *Errors
2626

27-
reverseClientBuilder func(context.Context, *wsConn) (context.Context, error)
28-
tracer Tracer
29-
methodTransformer MethodTransformer
30-
separator string
27+
reverseClientBuilder func(context.Context, *wsConn) (context.Context, error)
28+
tracer Tracer
29+
methodNameTransformer MethodNameTransformer
30+
separator string
3131
}
3232

3333
type ServerOption func(c *ServerConfig)
@@ -72,9 +72,9 @@ func WithNamespaceSeparator(separator string) ServerOption {
7272
}
7373
}
7474

75-
func WithMethodTransformer(methodTransformer MethodTransformer) ServerOption {
75+
func WithMethodNameTransformer(methodNameTransformer MethodNameTransformer) ServerOption {
7676
return func(c *ServerConfig) {
77-
c.methodTransformer = methodTransformer
77+
c.methodNameTransformer = methodNameTransformer
7878
}
7979
}
8080

rpc_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1757,7 +1757,7 @@ func TestCallWithMethodTransformer(t *testing.T) {
17571757
var matchFirstCap = regexp.MustCompile("(.)([A-Z][a-z]+)")
17581758
var matchAllCap = regexp.MustCompile("([a-z0-9])([A-Z])")
17591759

1760-
rpcServer := NewServer(WithMethodTransformer(func(method string) string {
1760+
rpcServer := NewServer(WithMethodNameTransformer(func(method string) string {
17611761
snake := matchFirstCap.ReplaceAllString(method, "${1}_${2}")
17621762
snake = matchAllCap.ReplaceAllString(snake, "${1}_${2}")
17631763
return strings.ToLower(snake)

0 commit comments

Comments
 (0)