Created
July 2, 2019 20:00
-
-
Save glaslos/d55ee43131cb983bd65df8c02ed32a7b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package glutton | |
import ( | |
"context" | |
"net" | |
"strings" | |
"go.uber.org/zap" | |
) | |
// HandleMemcache handles a Memcache connection | |
func (g *Glutton) HandleMemcache(ctx context.Context, conn net.Conn) error { | |
var err error | |
defer func() { | |
err = conn.Close() | |
if err != nil { | |
g.logger.Error("Error", zap.String("handler", "memcache"), zap.Error(err)) | |
} | |
}() | |
buffer := make([]byte, 1024) | |
for { | |
g.updateConnectionTimeout(ctx, conn) | |
n, err := conn.Read(buffer) | |
if err == nil || n > 0 { | |
parts := strings.Split(string(buffer), "\r\n") | |
head := parts[0] | |
headParts := strings.Split(head, " ") | |
switch headParts[0] { | |
case "set": | |
case "get": | |
conn.Write([]byte("VALUE key flag 6\r\nbanana\r\nEND\r\n")) | |
} | |
} else { | |
break | |
} | |
} | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment