Created plugin for PING command

This commit is contained in:
Kelvin Clement Mwinuka
2023-07-04 04:59:14 +08:00
parent 3043923c85
commit 3f39a23f13
2 changed files with 49 additions and 0 deletions

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