Skip to content
This repository was archived by the owner on Aug 15, 2022. It is now read-only.

Commit d11fb22

Browse files
committed
feat: made random id generator customizable
1 parent deb9209 commit d11fb22

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

server/server.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type Server struct {
1414
Events map[string]ConnectionHandler
1515
connections []Socket
1616
doListen bool
17+
RandFunc func() int
1718
}
1819

1920
var emptySocket = Socket{}
@@ -59,7 +60,7 @@ func (s *Server) Listen() error {
5960

6061
func (s *Server) newConnection(c net.Conn) (int, Socket) {
6162
sLocation := len(s.connections)
62-
socket := Socket{c, map[string]event.Handler{}, utils.RandomID()}
63+
socket := Socket{c, map[string]event.Handler{}, s.RandFunc()}
6364
s.connections = append(s.connections, socket)
6465
if val, ok := s.Events[events.Connection]; ok {
6566
val(socket)
@@ -72,7 +73,7 @@ func (s *Server) StopListening() {
7273
}
7374

7475
func Create(config Config) Server {
75-
return Server{Config: config, Events: make(map[string]ConnectionHandler)}
76+
return Server{Config: config, Events: make(map[string]ConnectionHandler), RandFunc: utils.RandomID}
7677
}
7778

7879
type ConnectionHandler func(Socket)

0 commit comments

Comments
 (0)