From fc605a7a475af27d0edeb18e76f1a59dcd258942 Mon Sep 17 00:00:00 2001 From: des <18638715007@163.com> Date: Tue, 17 Mar 2026 18:40:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=8F=E5=B7=A5=E5=85=B7=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bluePrint.go | 14 ------ cfg.yaml | 8 ++++ go.mod | 9 ++-- go.sum | 10 ++++ interface.go | 5 -- main.go | 110 +++++++++++++++++++++++++++++++++++++++++++- pasture/dog.go | 21 --------- pasture/sheep.go | 13 ------ zire.code-workspace | 27 +++++++++++ 9 files changed, 157 insertions(+), 60 deletions(-) delete mode 100644 bluePrint.go create mode 100644 cfg.yaml create mode 100644 go.sum delete mode 100644 interface.go delete mode 100644 pasture/dog.go delete mode 100644 pasture/sheep.go create mode 100644 zire.code-workspace diff --git a/bluePrint.go b/bluePrint.go deleted file mode 100644 index 67ceb13..0000000 --- a/bluePrint.go +++ /dev/null @@ -1,14 +0,0 @@ -package lab - -import ( - "github.com/zire" -) - -type Application struct{} - -func (a *Application) start() {} - -func test() { - app := zire.Karmaforge[Application]() - app.start() -} diff --git a/cfg.yaml b/cfg.yaml new file mode 100644 index 0000000..342e466 --- /dev/null +++ b/cfg.yaml @@ -0,0 +1,8 @@ +source: .\logistics-api\target\logistics-api-0.0.1.jar +target: /mnt/jkd-test/java +workJarName: jkd-api-0.0.1.jar +server: + host: 139.159.201.203 + prot: 22 + user: root + passwd: 3edc@EDC \ No newline at end of file diff --git a/go.mod b/go.mod index aaa6b39..2d98f15 100644 --- a/go.mod +++ b/go.mod @@ -1,11 +1,10 @@ module example -go 1.25 +go 1.25.0 require ( - github.com/zire v0.0.0 -) -replace ( - github.com/zire v0.0.0 => /home/nobara/projects/zire + golang.org/x/crypto v0.49.0 + gopkg.in/yaml.v3 v3.0.1 ) +require golang.org/x/sys v0.42.0 // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..bb0a3da --- /dev/null +++ b/go.sum @@ -0,0 +1,10 @@ +golang.org/x/crypto v0.49.0 h1:+Ng2ULVvLHnJ/ZFEq4KdcDd/cfjrrjjNSXNzxg0Y4U4= +golang.org/x/crypto v0.49.0/go.mod h1:ErX4dUh2UM+CFYiXZRTcMpEcN8b/1gxEuv3nODoYtCA= +golang.org/x/sys v0.42.0 h1:omrd2nAlyT5ESRdCLYdm3+fMfNFE/+Rf4bDIQImRJeo= +golang.org/x/sys v0.42.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= +golang.org/x/term v0.41.0 h1:QCgPso/Q3RTJx2Th4bDLqML4W6iJiaXFq2/ftQF13YU= +golang.org/x/term v0.41.0/go.mod h1:3pfBgksrReYfZ5lvYM0kSO0LIkAl4Yl2bXOkKP7Ec2A= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/interface.go b/interface.go deleted file mode 100644 index 0e726f3..0000000 --- a/interface.go +++ /dev/null @@ -1,5 +0,0 @@ -package lab - -type Animal interface { - sound() string -} diff --git a/main.go b/main.go index 44a96af..e6e5d9c 100644 --- a/main.go +++ b/main.go @@ -1,3 +1,109 @@ -package lab +package main -func main() {} +import ( + "bufio" + "fmt" + "io" + "os" + + "golang.org/x/crypto/ssh" + "gopkg.in/yaml.v3" +) + +const sep = string(os.PathSeparator) + +type Cfg struct { + Source string + Server struct { + Host string + Port string + User string + Passwd string + Target string + WorkJarName string + } +} + +func main() { + data, err := os.ReadFile("." + sep + "cfg.yaml") + if err != nil { + if os.IsNotExist(err) { + fmt.Println("在当前目录没有找到 cfg.yaml 配置文件") + panic(err) + } else { + panic(err) + } + } + cfg := Cfg{} + err = yaml.Unmarshal(data, &cfg) + if err != nil { + fmt.Printf("解析 yaml 文件失败,请确认文件内容是否是合法的 yaml") + panic(err) + } + _, err = os.Stat(cfg.Source) + if err != nil { + if os.IsNotExist(err) { + fmt.Println("没有找到 source 目标文件 - [" + cfg.Source + "]") + panic(err) + } else { + panic(err) + } + } + + srv := cfg.Server + + sshCfg := &ssh.ClientConfig{ + User: srv.User, + Auth: []ssh.AuthMethod{ + ssh.Password(srv.Passwd), + }, + HostKeyCallback: ssh.InsecureIgnoreHostKey(), + } + sc, err := ssh.Dial("tcp", fmt.Sprintf("%s:%s", srv.Host, srv.Port), sshCfg) + if err != nil { + fmt.Println("创建链接失败") + panic(err) + } + s, err := sc.NewSession() + if err != nil { + fmt.Println("创建会话失败") + panic(err) + } + defer s.Close() + in, err := s.StdinPipe() + if err != nil { + fmt.Println("获取输入管道失败") + panic(err) + } + out, err := s.StdoutPipe() + if err != nil { + fmt.Println("获取输出管道失败") + panic(err) + } + s.Shell() + fmt.Println("尝试输入指令") + fmt.Fprintln(in, "pwd") + fmt.Fprintln(in, "cd /mnt/jkd-test/java") + fmt.Fprintln(in, "ls -l") + fmt.Println("指令输入完毕") + scanner := bufio.NewScanner(out) + for scanner.Scan() { + fmt.Println(scanner.Text()) + } + +} + +type SshUtil struct { + in io.Writer + out io.Reader + sca *bufio.Scanner +} + +func NewSshUtil(in io.Writer, out io.Reader) { +} + +func (s SshUtil) command(args string) chan string { + result := make(chan string) + fmt.Fprintln(s.in, args) + return result +} diff --git a/pasture/dog.go b/pasture/dog.go deleted file mode 100644 index 5c62e63..0000000 --- a/pasture/dog.go +++ /dev/null @@ -1,21 +0,0 @@ -package pasture - -type Dog struct { - lines string - weapon string -} - -func (d *Dog) Sound() string { - return d.lines -} - -func (d *Dog) Dangers() bool { - if len(d.weapon) == 0 { - return false - } - return true -} - -func NewDog(line string) *Dog { - return &Dog{lines: line} -} diff --git a/pasture/sheep.go b/pasture/sheep.go deleted file mode 100644 index 3885458..0000000 --- a/pasture/sheep.go +++ /dev/null @@ -1,13 +0,0 @@ -package pasture - -type Sheep struct { - lines string -} - -func (s *Sheep) Sound() string { - return s.lines -} - -func NewSheep(line string) *Sheep { - return &Sheep{lines: line} -} diff --git a/zire.code-workspace b/zire.code-workspace new file mode 100644 index 0000000..ba4d8f9 --- /dev/null +++ b/zire.code-workspace @@ -0,0 +1,27 @@ +{ + "folders": [ + { + "path": "." + } + ], + "settings": { + "terminal.integrated.env.windows": { + "PATH": "C:\\Users\\Administrator\\.sdk\\go\\1.26\\go\\bin;${$env:PATH}" + }, + "go.goroot": "C:\\Users\\Administrator\\.sdk\\go\\1.26\\go", + }, + "launch": { + "version": "0.2.0", + "configurations": [ + { + "name": "Launch", + "type": "go", + "request": "launch", + "mode": "auto", + "program": "${workspaceFolder}", + "cwd": "C:\\Users\\Administrator\\projects\\jkd-tree\\logistics" + } + + ] + } +} \ No newline at end of file