mirror of
https://github.com/EchoVault/SugarDB.git
synced 2025-10-14 04:03:50 +08:00
Scrapped plugin design in favour of simple command interfaces.
Setup docker build process for running server. Deleted test files.
This commit is contained in:
43
server/command_ping.go
Normal file
43
server/command_ping.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package main
|
||||
|
||||
import "bufio"
|
||||
|
||||
type PingCommand struct {
|
||||
name string
|
||||
commands []string
|
||||
description string
|
||||
}
|
||||
|
||||
func (p *PingCommand) Name() string {
|
||||
return p.name
|
||||
}
|
||||
|
||||
func (p *PingCommand) Commands() []string {
|
||||
return p.commands
|
||||
}
|
||||
|
||||
func (p *PingCommand) Description() string {
|
||||
return p.description
|
||||
}
|
||||
|
||||
func (p *PingCommand) HandleCommand(cmd []string, server *Server, conn *bufio.Writer) {
|
||||
switch len(cmd) {
|
||||
default:
|
||||
conn.Write([]byte("-Error wrong number of arguments for PING command\r\n\n"))
|
||||
conn.Flush()
|
||||
case 1:
|
||||
conn.Write([]byte("+PONG\r\n\n"))
|
||||
conn.Flush()
|
||||
case 2:
|
||||
conn.Write([]byte("+" + cmd[1] + "\r\n\n"))
|
||||
conn.Flush()
|
||||
}
|
||||
}
|
||||
|
||||
func NewPingCommand() *PingCommand {
|
||||
return &PingCommand{
|
||||
name: "PingCommand",
|
||||
commands: []string{"ping"},
|
||||
description: "Handle PING command",
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user