mirror of
https://github.com/veops/oneterm.git
synced 2025-10-08 08:40:07 +08:00
feat(backend): Add telnet protocol support
This commit is contained in:
34
backend/internal/connector/protocols/db/postgresql.go
Normal file
34
backend/internal/connector/protocols/db/postgresql.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/veops/oneterm/internal/model"
|
||||
)
|
||||
|
||||
// getPostgreSQLConfig returns PostgreSQL client configuration
|
||||
func getPostgreSQLConfig(ip string, port int, account *model.Account) DBClientConfig {
|
||||
// Set PGPASSWORD environment variable instead of using -W
|
||||
os.Setenv("PGPASSWORD", account.Password)
|
||||
|
||||
args := []string{
|
||||
"-h", ip,
|
||||
"-p", fmt.Sprintf("%d", port),
|
||||
"-U", account.Account,
|
||||
"postgres", // Default database name
|
||||
}
|
||||
|
||||
// Add database name if specified in the account.Account field (username/database format)
|
||||
parts := strings.Split(account.Account, "/")
|
||||
if len(parts) > 1 {
|
||||
args = append(args, "-d", parts[1])
|
||||
}
|
||||
|
||||
return DBClientConfig{
|
||||
Command: "psql",
|
||||
Args: args,
|
||||
ExitAliases: []string{"\\q", "exit", "quit"},
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user