Skip to content

Commit d562ee8

Browse files
committed
config: 更新结构
1 parent 77ad018 commit d562ee8

5 files changed

Lines changed: 64 additions & 110 deletions

File tree

cmd/wutils/main.go

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -53,31 +53,42 @@ var (
5353
Level: "info",
5454
Format: "json",
5555
},
56-
Runner: runner.RunnerConfig{
57-
MaxWorkers: 4,
58-
Timeout: "30s",
59-
},
60-
Parallel: struct {
61-
Dsg bool
62-
Ol bool
63-
}{Dsg: true, Ol: true},
64-
Dsg: struct {
65-
Disk []string `required:"true"`
66-
Delay int `default:"30"`
67-
}{Disk: []string{"E:"}, Delay: 30},
68-
Ol: struct {
69-
Delay int `default:"2"`
70-
Patterns []struct {
71-
Title string
72-
Opacity byte
56+
Refresh: 10,
57+
Cmd: struct {
58+
Dsg struct {
59+
Parallel bool
60+
Disk []string `required:"true"`
61+
Delay int `default:"30"`
62+
}
63+
Ol struct {
64+
Parallel bool
65+
Delay int `default:"2"`
66+
Patterns []struct {
67+
Title string
68+
Opacity byte
69+
}
7370
}
74-
}{Delay: 2, Patterns: []struct {
75-
Title string
76-
Opacity byte
7771
}{
78-
{Title: "(XY|xy)plorer", Opacity: 200},
79-
{Title: "设置$", Opacity: 220},
80-
}},
72+
Dsg: struct {
73+
Parallel bool
74+
Disk []string `required:"true"`
75+
Delay int `default:"30"`
76+
}{Parallel: true, Disk: []string{"E:"}, Delay: 30},
77+
Ol: struct {
78+
Parallel bool
79+
Delay int `default:"2"`
80+
Patterns []struct {
81+
Title string
82+
Opacity byte
83+
}
84+
}{Parallel: true, Delay: 2, Patterns: []struct {
85+
Title string
86+
Opacity byte
87+
}{
88+
{Title: "(XY|xy)plorer", Opacity: 200},
89+
{Title: "设置$", Opacity: 220},
90+
}},
91+
},
8192
}
8293
data, err := yaml.Marshal(&defaultConfig)
8394
if err != nil {
@@ -145,10 +156,10 @@ var (
145156
Aliases: []string{"pl"},
146157
Usage: "并行+后台执行任务 (配置取自wutils.yml)",
147158
Action: func(cCtx *cli.Context) (err error) {
148-
if kr.Config.Parallel.Dsg {
159+
if kr.Config.Cmd.Dsg.Parallel {
149160
go kr.Dsg()
150161
}
151-
if kr.Config.Parallel.Ol {
162+
if kr.Config.Cmd.Ol.Parallel {
152163
kr.Ol()
153164
}
154165

cmd/wutils/runner/configs.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,22 @@ type RunnerConfig struct {
1818
}
1919

2020
type Config struct {
21-
App AppConfig
22-
Logging LoggingConfig
23-
Runner RunnerConfig
24-
Parallel struct {
25-
Dsg bool
26-
Ol bool
27-
}
28-
Dsg struct {
29-
Disk []string `required:"true"`
30-
Delay int `default:"30"`
31-
} `yaml:"dsg" required:"true"`
32-
Ol struct {
33-
Delay int `default:"2"`
34-
Patterns []struct {
35-
Title string
36-
Opacity byte
21+
App AppConfig
22+
Logging LoggingConfig
23+
Refresh int `default:"10"`
24+
Cmd struct {
25+
Dsg struct {
26+
Parallel bool
27+
Disk []string `required:"true"`
28+
Delay int `default:"30"`
29+
}
30+
Ol struct {
31+
Parallel bool
32+
Delay int `default:"2"`
33+
Patterns []struct {
34+
Title string
35+
Opacity byte
36+
}
3737
}
3838
}
3939
}

cmd/wutils/runner/keep_runner.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,16 @@ func NewKeepRunner(logger *logrus.Logger, configPath string) *Scope {
3232
func (s *Scope) init() {
3333
for {
3434
_ = configor.Load(&s.Config, s.ConfigPath)
35-
if s.Config.Runner.Refresh < 1 {
36-
s.Config.Runner.Refresh = 1
35+
if s.Config.Refresh < 1 {
36+
s.Config.Refresh = 1
3737
}
38-
time.Sleep(time.Second * time.Duration(s.Config.Runner.Refresh))
38+
time.Sleep(time.Second * time.Duration(s.Config.Refresh))
3939
}
4040
}
4141

4242
// Dsg 执行 DSG 任务
4343
func (s *Scope) Dsg() {
44-
s.Logger.Infoln(s.Config.Dsg)
44+
s.Logger.Infoln(s.Config.Cmd.Dsg)
4545
writeString := func(disk string) {
4646
f := strings.Join([]string{disk, ".dsg"}, "/")
4747

@@ -54,24 +54,24 @@ func (s *Scope) Dsg() {
5454
}
5555

5656
for true {
57-
collection.ForEach(s.Config.Dsg.Disk, func(i int, v string) {
57+
collection.ForEach(s.Config.Cmd.Dsg.Disk, func(i int, v string) {
5858
go writeString(v)
5959
})
60-
time.Sleep(time.Second * time.Duration(s.Config.Dsg.Delay))
60+
time.Sleep(time.Second * time.Duration(s.Config.Cmd.Dsg.Delay))
6161
}
6262
}
6363

6464
// Ol 执行 OL 任务
6565
func (s *Scope) Ol() {
66-
s.Logger.Infoln(s.Config.Ol)
66+
s.Logger.Infoln(s.Config.Cmd.Ol)
6767

6868
for true {
6969
windows := os2.GetEnumWindowsInfo(&os2.EnumWindowsFilter{
7070
IgnoreNoTitled: true,
7171
IgnoreInvisible: true,
7272
})
7373
collection.ForEach(windows, func(i int, window *os2.EnumWindowsResult) {
74-
collection.ForEach(s.Config.Ol.Patterns, func(ii int, pattern struct {
74+
collection.ForEach(s.Config.Cmd.Ol.Patterns, func(ii int, pattern struct {
7575
Title string
7676
Opacity byte
7777
}) {
@@ -83,7 +83,7 @@ func (s *Scope) Ol() {
8383
}
8484
})
8585
})
86-
time.Sleep(time.Second * time.Duration(s.Config.Ol.Delay))
86+
time.Sleep(time.Second * time.Duration(s.Config.Cmd.Ol.Delay))
8787
}
8888
}
8989

cmd/wutils/zip/crack.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ func getPasswordFilePath() (string, error) {
3030
if err := os.MkdirAll(dir, 0755); err != nil {
3131
return "", fmt.Errorf("failed to create directory: %w", err)
3232
}
33-
defaultContent := []byte("# Add your password dictionary here, one password per line\n")
33+
defaultContent := []byte("# Add your password dictionary here, one password per line\n" +
34+
"123456\npassword\n" +
35+
"admin\n12345678\n")
3436
if err := os.WriteFile(path, defaultContent, 0644); err != nil {
3537
return "", fmt.Errorf("failed to create password file: %w", err)
3638
}

config/app.yml

Lines changed: 0 additions & 59 deletions
This file was deleted.

0 commit comments

Comments
 (0)