forked from googollee/go-socket.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
namespace.go
47 lines (39 loc) · 950 Bytes
/
namespace.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package socketio
// Namespace is the name space of a socket.io handler.
type Namespace interface {
// Name returns the name of the namespace.
Name() string
// Of returns the namespace with given name.
Of(name string) Namespace
// On registers the function f to handle an event.
On(event string, f interface{}) error
}
type namespace struct {
*baseHandler
root map[string]Namespace
}
func newNamespace(broadcast BroadcastAdaptor) *namespace {
ret := &namespace{
baseHandler: newBaseHandler("", broadcast),
root: make(map[string]Namespace),
}
ret.root[ret.Name()] = ret
return ret
}
func (n *namespace) Name() string {
return n.baseHandler.name
}
func (n *namespace) Of(name string) Namespace {
if name == "/" {
name = ""
}
if ret, ok := n.root[name]; ok {
return ret
}
ret := &namespace{
baseHandler: newBaseHandler(name, n.baseHandler.broadcast),
root: n.root,
}
n.root[name] = ret
return ret
}