// you must call the function before calling console.Init // goroutine not safe func Register(name string, help string, f interface{}, server *chanrpc.Server) { for _, c := range commands { if c.name() == name { log.Fatal("command %v is already registered", name) } } server.Register(name, f) c := new(ExternalCommand) c._name = name c._help = help c.server = server commands = append(commands, c) }
// you must call the function before calling console.Init,也就是在leaf.Run之前 // goroutine not safe // 注册命令 func Register(name string, help string, f interface{}, server *chanrpc.Server) { //判断命令是否存在 for _, c := range commands { if c.name() == name { log.Fatal("command %v is already registered", name) } } //注册f(函数) server.Register(name, f) //将命令注册进RPC服务器内 c := new(ExternalCommand) //创建一个外部命令 c._name = name //保存命令名字 c._help = help //保存命令帮助 c.server = server //保存命令服务(一个rpc服务器) commands = append(commands, c) //添加命令到命令列表中 }