Skip to content

Commit fefaab1

Browse files
committed
feat: add reverseHandlersFormatter to Config and update websocketClient to use it
1 parent bbbae86 commit fefaab1

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

client.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,11 @@ func websocketClient(ctx context.Context, addr string, namespace string, outs []
305305

306306
var hnd reqestHandler
307307
if len(config.reverseHandlers) > 0 {
308-
h := makeHandler(defaultServerConfig())
308+
sc := defaultServerConfig()
309+
if config.reverseHandlersFormatter != nil {
310+
sc.methodNameFormatter = config.reverseHandlersFormatter
311+
}
312+
h := makeHandler(sc)
309313
h.aliasedMethods = config.aliasedHandlerMethods
310314
for _, reverseHandler := range config.reverseHandlers {
311315
h.register(reverseHandler.ns, reverseHandler.hnd)

options.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ type Config struct {
2323
paramEncoders map[reflect.Type]ParamEncoder
2424
errors *Errors
2525

26-
reverseHandlers []clientHandler
27-
aliasedHandlerMethods map[string]string
26+
reverseHandlers []clientHandler
27+
reverseHandlersFormatter MethodNameFormatter
28+
aliasedHandlerMethods map[string]string
2829

2930
httpClient *http.Client
3031

@@ -101,6 +102,13 @@ func WithClientHandler(ns string, hnd interface{}) func(c *Config) {
101102
}
102103
}
103104

105+
// Just like WithMethodNameFormatter, but for client handlers.
106+
func WithClientHandlerFormatter(namer MethodNameFormatter) func(c *Config) {
107+
return func(c *Config) {
108+
c.reverseHandlersFormatter = namer
109+
}
110+
}
111+
104112
// WithClientHandlerAlias creates an alias for a client HANDLER method - for handlers created
105113
// with WithClientHandler
106114
func WithClientHandlerAlias(alias, original string) func(c *Config) {

0 commit comments

Comments
 (0)