小工具初始化

This commit is contained in:
des
2026-03-17 18:40:21 +08:00
parent 1271ceeee7
commit fc605a7a47
9 changed files with 157 additions and 60 deletions

View File

@@ -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()
}

8
cfg.yaml Normal file
View File

@@ -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

9
go.mod
View File

@@ -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

10
go.sum Normal file
View File

@@ -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=

View File

@@ -1,5 +0,0 @@
package lab
type Animal interface {
sound() string
}

110
main.go
View File

@@ -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
}

View File

@@ -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}
}

View File

@@ -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}
}

27
zire.code-workspace Normal file
View File

@@ -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"
}
]
}
}