mirror of
https://github.com/EchoVault/SugarDB.git
synced 2025-10-16 04:50:45 +08:00
Created plugin for PING command
This commit is contained in:
48
server/plugins/commands/ping/ping.go
Normal file
48
server/plugins/commands/ping/ping.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package main
|
||||
|
||||
import "bufio"
|
||||
|
||||
type Server interface {
|
||||
GetData(key string) interface{}
|
||||
SetData(key string, value interface{})
|
||||
}
|
||||
|
||||
type plugin struct {
|
||||
name string
|
||||
commands []string
|
||||
description string
|
||||
}
|
||||
|
||||
var Plugin plugin
|
||||
|
||||
func (p *plugin) Name() string {
|
||||
return p.name
|
||||
}
|
||||
|
||||
func (p *plugin) Commands() []string {
|
||||
return p.commands
|
||||
}
|
||||
|
||||
func (p *plugin) Description() string {
|
||||
return p.description
|
||||
}
|
||||
|
||||
func (p *plugin) HandleCommand(cmd []string, server interface{}, 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 init() {
|
||||
Plugin.name = "PingCommand"
|
||||
Plugin.commands = []string{"ping"}
|
||||
Plugin.description = "Handle PING command"
|
||||
}
|
Reference in New Issue
Block a user