diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..304c3d7 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "go.inferGopath": false +} \ No newline at end of file diff --git a/command/index.go b/command/index.go index 6e6f0c6..0484681 100644 --- a/command/index.go +++ b/command/index.go @@ -11,7 +11,7 @@ import ( 第一个参数是执行的目录,第二个参数是命令 */ -func Run(content string,direct string) { +func Run(content string, direct string) { param := strings.Split(direct, " ") cmd := exec.Command(param[0], param[1:]...) cmd.Dir = content diff --git a/file/index.go b/file/index.go index 94e6cf6..887bed5 100644 --- a/file/index.go +++ b/file/index.go @@ -1,6 +1,6 @@ package file -import( +import ( "os" "path" "strings" diff --git a/go.mod b/go.mod index cbcac96..a261b64 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,7 @@ -module github.com/MrYZhou/outil +module github.com/MrYZhou/outil -go 1.19 \ No newline at end of file +go 1.19 + +require golang.org/x/crypto v0.4.0 + +require golang.org/x/sys v0.3.0 // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..6db1f2a --- /dev/null +++ b/go.sum @@ -0,0 +1,4 @@ +golang.org/x/crypto v0.4.0 h1:UVQgzMY87xqpKNgb+kDsll2Igd33HszWHFLmpaRMq/8= +golang.org/x/crypto v0.4.0/go.mod h1:3quD/ATkf6oY+rnes5c3ExXTbLc8mueNue5/DoinL80= +golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ= +golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/ssh/index.go b/ssh/index.go index 781adca..736a3f7 100644 --- a/ssh/index.go +++ b/ssh/index.go @@ -2,7 +2,6 @@ package ssh import ( "net" - "os" "golang.org/x/crypto/ssh" ) @@ -11,7 +10,7 @@ import ( type Cli struct { user string password string - addr string + host string client *ssh.Client LastResult string } @@ -23,7 +22,7 @@ func (c *Cli) Connect() (*Cli, error) { config.User = c.user config.Auth = []ssh.AuthMethod{ssh.Password(c.password)} config.HostKeyCallback = func(hostname string, remote net.Addr, key ssh.PublicKey) error { return nil } - client, err := ssh.Dial("tcp", c.addr, config) + client, err := ssh.Dial("tcp", c.host, config) if nil != err { return c, err } @@ -50,30 +49,15 @@ func (c Cli) Run(shell string) (string, error) { return c.LastResult, err } -func Server() Cli { - addr := os.Getenv("addr") - user := os.Getenv("user") - password := os.Getenv("password") +func Server(host string, user string, password string) Cli { + cli := Cli{ - addr: addr, - user: user, - password:password, + host: host, + user: user, + password: password, } c, _ := cli.Connect() defer c.client.Close() return cli } - -// func Server(addr string,user string, password string) Cli { - -// cli := Cli{ -// addr: addr, -// user: user, -// password:password, -// } -// c, _ := cli.Connect() - -// defer c.client.Close() -// return cli -// }