1 Star 2 Fork 3

kristas/booting-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
ssh_client.go 963 Bytes
一键复制 编辑 原始数据 按行查看 历史
package ssh
import (
"context"
"gitee.com/kristas/booting-go/framework/logging"
"golang.org/x/crypto/ssh"
"net"
)
type Config struct {
IP string `json:"ip" yaml:"ip"`
Username string `json:"username" yaml:"username"`
Password string `json:"password" yaml:"password"`
}
func BuildSSHClient(config Config) *Client {
client, err := DialWithPasswd(config.IP, config.Username, config.Password)
if err != nil {
panic(err)
}
//sshSuccessEcho, err := client.Cmd(`echo "SSH login success!"`).Output()
//if err != nil {
// panic(err)
//}
//log.Println(string(sshSuccessEcho))
return client
}
var log logging.Logger
type Dialer struct {
Client *ssh.Client
_ *context.Context
}
func NewDialer(client *Client) *Dialer {
return &Dialer{Client: client.Client}
}
func (r *Dialer) Dial(context context.Context, addr string) (net.Conn, error) {
log = logging.GetLog()
log.Infof("[SSH] Dial [%s]", addr)
return r.Client.Dial("tcp", addr)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/kristas/booting-go.git
git@gitee.com:kristas/booting-go.git
kristas
booting-go
booting-go
v1.2.8

搜索帮助