diff options
Diffstat (limited to 'rpc.go')
-rw-r--r-- | rpc.go | 20 |
1 files changed, 19 insertions, 1 deletions
@@ -1,6 +1,9 @@ package tanja -import "reflect" +import ( + "reflect" + "strings" +) // Registers a pattern for each of the methods of 'obj'. The method will be // called from ses.Dispatch() (and thus ses.Run() if you use that) whenever a @@ -156,3 +159,18 @@ func regRPCGenCallback(mt reflect.Type, mv reflect.Value, offset int, willReply } } } + +// Handy wrapper for RegRPC(), where each method-to-be-registered has a common +// prefix in the name, and where the pattern consists of another prefix + the +// rest of the method name. (The source code is easier to understand than this +// explanation, really) +func (s *Session) RegPrefix(obj interface{}, pat Tuple, prefix string, tolower bool) []*Registration { + return s.RegRPC(obj, func(n string) Tuple { + if !strings.HasPrefix(n, prefix) { + return nil + } else if tolower { + return append(pat, Element{strings.ToLower(n[len(prefix):])}) + } + return append(pat, Element{n[len(prefix):]}) + }) +} |