Skip to content

Conversation

thani-sh
Copy link
Contributor

No description provided.

 - move handlers into separate files
 - use interfaces for handlers, etc
 - update README.md files
@arunoda
Copy link
Member

arunoda commented Feb 18, 2015

Machan, how about this one. Then testing and everything will be simple.

type MessageHandle func(*Server, Response, Message) error

// These are the handles

func connectHandle(s *Server, res Response, m Message) error {
 return res.WriteJSON(map[string]string{
   "msg":     "connected",
   "session": random.Id(17),
 })
}

func pingHandle(s *Server, res Response, m Message) error {
 ...
}

func methodHandle(s *Server, res Response, m Message) error {
 ...
}

DDPHandlers:= map[string]MessageHandle {
  "connect": connectHandle,
  "ping": pingHandle,
  "method": methodHandle
}

// In the server.

if handler, ok := DDPHandlers[msg.Msg]; ok {
  go handler(s, res, msg)
} else {
  break
}

@thani-sh
Copy link
Contributor Author

Yeah. Code is a lot simpler this way.

On Wed, Feb 18, 2015, 20:48 Arunoda Susiripala notifications@github.com
wrote:

Machan, how about this one. Then testing and everything will be simple.

type MessageHandle func(*Server, Response, Message) error
// These are the handles
func connectHandle(s *Server, res Response, m Message) error {
return res.WriteJSON(map[string]string{
"msg": "connected",
"session": random.Id(17),
})
}
func pingHandle(s *Server, res Response, m Message) error {
...
}
func methodHandle(s *Server, res Response, m Message) error {
...
}
DDPHandlers := map[string]MessageHandle{
"connect": connectHandle,
"ping": pingHandle,
"method": methodHandle
}
// In the server.
if handler, ok := DDPHandlers[msg.Msg]; ok {
go handler(s, res, msg)
} else {
break
}


Reply to this email directly or view it on GitHub
#3 (comment).

@arunoda
Copy link
Member

arunoda commented Feb 18, 2015

great.

On Wed Feb 18 2015 at 9:18:03 PM Muhammed Thanish notifications@github.com
wrote:

Yeah. Code is a lot simpler this way.

On Wed, Feb 18, 2015, 20:48 Arunoda Susiripala notifications@github.com
wrote:

Machan, how about this one. Then testing and everything will be simple.

type MessageHandle func(*Server, Response, Message) error
// These are the handles
func connectHandle(s *Server, res Response, m Message) error {
return res.WriteJSON(map[string]string{
"msg": "connected",
"session": random.Id(17),
})
}
func pingHandle(s *Server, res Response, m Message) error {
...
}
func methodHandle(s *Server, res Response, m Message) error {
...
}
DDPHandlers := map[string]MessageHandle{
"connect": connectHandle,
"ping": pingHandle,
"method": methodHandle
}
// In the server.
if handler, ok := DDPHandlers[msg.Msg]; ok {
go handler(s, res, msg)
} else {
break
}


Reply to this email directly or view it on GitHub
#3 (comment).


Reply to this email directly or view it on GitHub
#3 (comment).

@thani-sh
Copy link
Contributor Author

Added some integration tests

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicate.

@thani-sh thani-sh force-pushed the refactor-handlers branch 2 times, most recently from b51ae7e to 535d079 Compare February 19, 2015 07:41
arunoda added a commit that referenced this pull request Feb 19, 2015
@arunoda arunoda merged commit 32b68e9 into master Feb 19, 2015
@arunoda arunoda deleted the refactor-handlers branch February 19, 2015 09:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants