Skip to content

Commit ac145e3

Browse files
committed
fix:修复psql连接问题
1 parent ea52c96 commit ac145e3

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

go-client/awaken.go

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"path/filepath"
1212
"regexp"
1313
"runtime"
14+
"strings"
1415
)
1516

1617
var cmd *exec.Cmd
@@ -33,6 +34,30 @@ func RemoveCurRdpFile() {
3334
}
3435
}
3536
}
37+
func StructureMacCommand(command string) string {
38+
command = strings.Trim(strings.ReplaceAll(command, "psql ", ""), `"`)
39+
psql := &PostgresqlInfo{}
40+
for _, v := range strings.Split(command, " ") {
41+
tp, val := strings.Split(v, "=")[0], strings.Split(v, "=")[1]
42+
switch tp {
43+
case "user":
44+
psql.User = val
45+
case "password":
46+
psql.Password = val
47+
case "host":
48+
psql.Host = val
49+
case "port":
50+
psql.Port = val
51+
case "dbname":
52+
psql.DBName = val
53+
}
54+
}
55+
macCommand := fmt.Sprintf(
56+
"PGPASSWORD=%s psql -U %s -h %s -p %s -d %s",
57+
psql.Password, psql.User, psql.Host, psql.Port, psql.DBName,
58+
)
59+
return macCommand
60+
}
3661

3762
type Token struct {
3863
Ip string `json:"ip"`
@@ -50,6 +75,14 @@ type Info struct {
5075
Config string `json:"config"`
5176
}
5277

78+
type PostgresqlInfo struct {
79+
User string `json:"user"`
80+
Password string `json:"password"`
81+
Host string `json:"host"`
82+
Port string `json:"port"`
83+
DBName string `json:"dbname"`
84+
}
85+
5386
type Rouse struct {
5487
SysType string
5588
Info
@@ -118,11 +151,16 @@ func (r *Rouse) HandleDB() {
118151
// }
119152
//}
120153
if r.SysType == "windows" {
121-
cmd = exec.Command("cmd", "/c", "start cmd /k "+r.Command)
154+
cmd = exec.Command("cmd")
155+
//cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true, CmdLine: `/c start cmd /k ` + r.Command}
122156
} else {
157+
command := r.Command
158+
if r.Protocol == "postgresql" {
159+
command = StructureMacCommand(command)
160+
}
123161
cmd = exec.Command(
124162
"osascript", "-s", "h", "-e",
125-
fmt.Sprintf(`tell application "Terminal" to do script "%s"`, r.Command),
163+
fmt.Sprintf(`tell application "Terminal" to do script "%s"`, command),
126164
)
127165
}
128166
cmd.Run()

0 commit comments

Comments
 (0)