代码拉取完成,页面将自动刷新
package console
import (
"bufio"
"strings"
"gitee.com/nbcx/leaf/conf"
"gitee.com/nbcx/leaf/network"
"gitee.com/nbcx/leaf/network/tcp"
)
type Agent struct {
conn *tcp.TCPConn
reader *bufio.Reader
}
func newAgent(conn *tcp.TCPConn) network.Agent {
a := new(Agent)
a.conn = conn
a.reader = bufio.NewReader(conn)
return a
}
func (a *Agent) Run() {
for {
if conf.ConsolePrompt != "" {
a.conn.Write([]byte(conf.ConsolePrompt))
}
line, err := a.reader.ReadString('\n')
if err != nil {
break
}
line = strings.TrimSuffix(line[:len(line)-1], "\r")
args := strings.Fields(line)
if len(args) == 0 {
continue
}
if args[0] == "quit" {
break
}
var c Command
for _, _c := range commands {
if _c.name() == args[0] {
c = _c
break
}
}
if c == nil {
a.conn.Write([]byte("command not found, try `help` for help\r\n"))
continue
}
output := c.run(args[1:])
if output != "" {
a.conn.Write([]byte(output + "\r\n"))
}
}
}
func (a *Agent) OnClose() {}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。