Permalink
Browse files

Added a function to wrap a server request handler function.

  • Loading branch information...
1 parent f43a21c commit 019007776e69dca1e8407ca0970c21418c2d9ca3 @dustin committed Jun 26, 2012
Showing with 11 additions and 0 deletions.
  1. +11 −0 server/mc_conn_handler.go
View
11 server/mc_conn_handler.go
@@ -24,6 +24,12 @@ func (b BadMagic) Error() string {
return fmt.Sprintf("Bad magic: 0x%02x", b.was)
}
+type funcHandler func(*gomemcached.MCRequest) *gomemcached.MCResponse
+
+func (fh funcHandler) HandleMessage(msg *gomemcached.MCRequest) *gomemcached.MCResponse {
+ return fh(msg)
+}
+
// Request handler for doing server stuff.
type RequestHandler interface {
// Handle a message from the client.
@@ -33,6 +39,11 @@ type RequestHandler interface {
HandleMessage(*gomemcached.MCRequest) *gomemcached.MCResponse
}
+// Convert a request handler function as a RequestHandler.
+func FuncHandler(f func(*gomemcached.MCRequest) *gomemcached.MCResponse) RequestHandler {
+ return funcHandler(f)
+}
+
func HandleIO(s io.ReadWriteCloser, handler RequestHandler) {
defer s.Close()
for handleMessage(s, s, handler) {

0 comments on commit 0190077

Please sign in to comment.