Files
SugarDB/server/command_ping.go
Kelvin Clement Mwinuka d4a5997b30 Scrapped plugin design in favour of simple command interfaces.
Setup docker build process for running server.
Deleted test files.
2023-07-22 05:34:07 +08:00

44 lines
826 B
Go

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",
}
}