all: replace some cases of strings.SplitN with strings.Cut (#28446)

This commit is contained in:
Håvard Anda Estensen
2023-11-15 14:42:33 +01:00
committed by GitHub
parent db7895d3b6
commit a75a2d6db6
6 changed files with 20 additions and 22 deletions
+2 -2
View File
@@ -86,8 +86,8 @@ func (msg *jsonrpcMessage) isUnsubscribe() bool {
}
func (msg *jsonrpcMessage) namespace() string {
elem := strings.SplitN(msg.Method, serviceMethodSeparator, 2)
return elem[0]
before, _, _ := strings.Cut(msg.Method, serviceMethodSeparator)
return before
}
func (msg *jsonrpcMessage) String() string {
+3 -3
View File
@@ -93,13 +93,13 @@ func (r *serviceRegistry) registerName(name string, rcvr interface{}) error {
// callback returns the callback corresponding to the given RPC method name.
func (r *serviceRegistry) callback(method string) *callback {
elem := strings.SplitN(method, serviceMethodSeparator, 2)
if len(elem) != 2 {
before, after, found := strings.Cut(method, serviceMethodSeparator)
if !found {
return nil
}
r.mu.Lock()
defer r.mu.Unlock()
return r.services[elem[0]].callbacks[elem[1]]
return r.services[before].callbacks[after]
}
// subscription returns a subscription callback in the given service.