Spaces:
Running
Running
aurorax-neo
commited on
Commit
•
6ad1de1
1
Parent(s):
7303ec3
update
Browse files- conf/conf.go +0 -89
- internal/app/app.go +2 -4
- internal/conf/conf.go +1 -4
conf/conf.go
DELETED
@@ -1,89 +0,0 @@
|
|
1 |
-
package conf
|
2 |
-
|
3 |
-
import (
|
4 |
-
"context"
|
5 |
-
"fmt"
|
6 |
-
"github.com/joho/godotenv"
|
7 |
-
"kpl/pkg/logx"
|
8 |
-
"os"
|
9 |
-
"strconv"
|
10 |
-
)
|
11 |
-
|
12 |
-
var CONF = &conf{}
|
13 |
-
|
14 |
-
type Serv00 struct {
|
15 |
-
Host string
|
16 |
-
Port int
|
17 |
-
Username string
|
18 |
-
Password string
|
19 |
-
Cmd string
|
20 |
-
}
|
21 |
-
|
22 |
-
type conf struct {
|
23 |
-
Proxy string
|
24 |
-
Serv00s []Serv00
|
25 |
-
Serv00IntervalSec int
|
26 |
-
HgUrls []string
|
27 |
-
HgIntervalSec int
|
28 |
-
}
|
29 |
-
|
30 |
-
func Init(ctx context.Context) func(context.Context) {
|
31 |
-
_ = godotenv.Load()
|
32 |
-
index := 1
|
33 |
-
for {
|
34 |
-
url := os.Getenv(fmt.Sprint("HG_URL", index))
|
35 |
-
if url == "" {
|
36 |
-
break
|
37 |
-
}
|
38 |
-
CONF.HgUrls = append(CONF.HgUrls, url)
|
39 |
-
index++
|
40 |
-
}
|
41 |
-
index = 1
|
42 |
-
for {
|
43 |
-
host := os.Getenv(fmt.Sprint("SERV00_HOST", index))
|
44 |
-
username := os.Getenv(fmt.Sprint("SERV00_USERNAME", index))
|
45 |
-
password := os.Getenv(fmt.Sprint("SERV00_PASSWORD", index))
|
46 |
-
cmd := os.Getenv(fmt.Sprint("SERV00_CMD", index))
|
47 |
-
if host == "" {
|
48 |
-
break
|
49 |
-
}
|
50 |
-
if username == "" || password == "" || cmd == "" {
|
51 |
-
continue
|
52 |
-
}
|
53 |
-
CONF.Serv00s = append(CONF.Serv00s, Serv00{
|
54 |
-
Host: host,
|
55 |
-
Port: 22,
|
56 |
-
Username: username,
|
57 |
-
Password: password,
|
58 |
-
Cmd: cmd,
|
59 |
-
})
|
60 |
-
index++
|
61 |
-
}
|
62 |
-
CONF.Proxy = os.Getenv("PROXY")
|
63 |
-
hgIntervalSec := os.Getenv("HG_INTERVAL_SEC")
|
64 |
-
if hgIntervalSec == "" {
|
65 |
-
CONF.HgIntervalSec = 8
|
66 |
-
} else {
|
67 |
-
parseInt, err := strconv.ParseInt(hgIntervalSec, 10, 64)
|
68 |
-
if err != nil {
|
69 |
-
CONF.HgIntervalSec = 8
|
70 |
-
} else {
|
71 |
-
CONF.HgIntervalSec = int(parseInt)
|
72 |
-
}
|
73 |
-
}
|
74 |
-
serv00IntervalSec := os.Getenv("SERV00_INTERVAL_SEC")
|
75 |
-
if serv00IntervalSec == "" {
|
76 |
-
CONF.Serv00IntervalSec = 300
|
77 |
-
} else {
|
78 |
-
parseInt, err := strconv.ParseInt(serv00IntervalSec, 10, 64)
|
79 |
-
if err != nil {
|
80 |
-
CONF.Serv00IntervalSec = 300
|
81 |
-
} else {
|
82 |
-
CONF.Serv00IntervalSec = int(parseInt)
|
83 |
-
}
|
84 |
-
}
|
85 |
-
logx.WithContext(ctx).Infof("config loaded successfully")
|
86 |
-
|
87 |
-
return func(ctx context.Context) {
|
88 |
-
}
|
89 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
internal/app/app.go
CHANGED
@@ -21,14 +21,12 @@ func Run(ctx context.Context) {
|
|
21 |
cleanUp.Push(Start(ctx))
|
22 |
|
23 |
// 提示 保活列表
|
24 |
-
logx.WithContext(ctx).Info("hgUrls: ")
|
25 |
for i, url := range conf.CONF.HgUrls {
|
26 |
-
logx.WithContext(ctx).Info(i, ": ", url)
|
27 |
}
|
28 |
|
29 |
-
logx.WithContext(ctx).Info("serv00s: ")
|
30 |
for i, serv00 := range conf.CONF.Serv00s {
|
31 |
-
logx.WithContext(ctx).Info(i, ": ", serv00.Username, "@", serv00.Host, ":", serv00.Port)
|
32 |
}
|
33 |
|
34 |
AsyncTimingTask(time.Duration(conf.CONF.HgIntervalSec)*time.Second, func() {
|
|
|
21 |
cleanUp.Push(Start(ctx))
|
22 |
|
23 |
// 提示 保活列表
|
|
|
24 |
for i, url := range conf.CONF.HgUrls {
|
25 |
+
logx.WithContext(ctx).Info("HG_URL", i, ": ", url)
|
26 |
}
|
27 |
|
|
|
28 |
for i, serv00 := range conf.CONF.Serv00s {
|
29 |
+
logx.WithContext(ctx).Info("Serv00", i, ": ", serv00.Username, "@", serv00.Host, ":", serv00.Port)
|
30 |
}
|
31 |
|
32 |
AsyncTimingTask(time.Duration(conf.CONF.HgIntervalSec)*time.Second, func() {
|
internal/conf/conf.go
CHANGED
@@ -44,12 +44,9 @@ func Init(ctx context.Context) func(context.Context) {
|
|
44 |
username := os.Getenv(fmt.Sprint("SERV00_USERNAME", index))
|
45 |
password := os.Getenv(fmt.Sprint("SERV00_PASSWORD", index))
|
46 |
cmd := os.Getenv(fmt.Sprint("SERV00_CMD", index))
|
47 |
-
if host == "" {
|
48 |
break
|
49 |
}
|
50 |
-
if username == "" || password == "" || cmd == "" {
|
51 |
-
continue
|
52 |
-
}
|
53 |
CONF.Serv00s = append(CONF.Serv00s, Serv00{
|
54 |
Host: host,
|
55 |
Port: 22,
|
|
|
44 |
username := os.Getenv(fmt.Sprint("SERV00_USERNAME", index))
|
45 |
password := os.Getenv(fmt.Sprint("SERV00_PASSWORD", index))
|
46 |
cmd := os.Getenv(fmt.Sprint("SERV00_CMD", index))
|
47 |
+
if host == "" || username == "" || password == "" || cmd == "" {
|
48 |
break
|
49 |
}
|
|
|
|
|
|
|
50 |
CONF.Serv00s = append(CONF.Serv00s, Serv00{
|
51 |
Host: host,
|
52 |
Port: 22,
|