Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added a function to wrap a server request handler function.

  • Loading branch information...
commit 019007776e69dca1e8407ca0970c21418c2d9ca3 1 parent f43a21c
Dustin Sallings authored

Showing 1 changed file with 11 additions and 0 deletions. Show diff stats Hide diff stats

  1. +11 0 server/mc_conn_handler.go
11 server/mc_conn_handler.go
@@ -24,6 +24,12 @@ func (b BadMagic) Error() string {
24 24 return fmt.Sprintf("Bad magic: 0x%02x", b.was)
25 25 }
26 26
  27 +type funcHandler func(*gomemcached.MCRequest) *gomemcached.MCResponse
  28 +
  29 +func (fh funcHandler) HandleMessage(msg *gomemcached.MCRequest) *gomemcached.MCResponse {
  30 + return fh(msg)
  31 +}
  32 +
27 33 // Request handler for doing server stuff.
28 34 type RequestHandler interface {
29 35 // Handle a message from the client.
@@ -33,6 +39,11 @@ type RequestHandler interface {
33 39 HandleMessage(*gomemcached.MCRequest) *gomemcached.MCResponse
34 40 }
35 41
  42 +// Convert a request handler function as a RequestHandler.
  43 +func FuncHandler(f func(*gomemcached.MCRequest) *gomemcached.MCResponse) RequestHandler {
  44 + return funcHandler(f)
  45 +}
  46 +
36 47 func HandleIO(s io.ReadWriteCloser, handler RequestHandler) {
37 48 defer s.Close()
38 49 for handleMessage(s, s, handler) {

0 comments on commit 0190077

Please sign in to comment.
Something went wrong with that request. Please try again.