diff options
| author | chrislu <chris.lu@gmail.com> | 2022-08-07 01:34:36 -0700 |
|---|---|---|
| committer | chrislu <chris.lu@gmail.com> | 2022-08-07 01:34:36 -0700 |
| commit | 358ccb5e0eb2fd0d5f7f1bd6259dc5950df76526 (patch) | |
| tree | 8cf92b45ebf48e51f71b011b4b30f2d129ba9262 /weed/filer/postgres/postgres_store.go | |
| parent | 67814a5c79078e0fd6ca226501b7e48cb2e0558f (diff) | |
| parent | 3afda0c89c8faa584423b6b1b488cd18d1d42a88 (diff) | |
| download | seaweedfs-358ccb5e0eb2fd0d5f7f1bd6259dc5950df76526.tar.xz seaweedfs-358ccb5e0eb2fd0d5f7f1bd6259dc5950df76526.zip | |
Merge branch 'master' of https://github.com/seaweedfs/seaweedfs
Diffstat (limited to 'weed/filer/postgres/postgres_store.go')
| -rw-r--r-- | weed/filer/postgres/postgres_store.go | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/weed/filer/postgres/postgres_store.go b/weed/filer/postgres/postgres_store.go index ed38babcd..cacdbd864 100644 --- a/weed/filer/postgres/postgres_store.go +++ b/weed/filer/postgres/postgres_store.go @@ -3,6 +3,7 @@ package postgres import ( "database/sql" "fmt" + "strconv" "time" _ "github.com/lib/pq" @@ -11,10 +12,6 @@ import ( "github.com/seaweedfs/seaweedfs/weed/util" ) -const ( - CONNECTION_URL_PATTERN = "host=%s port=%d sslmode=%s connect_timeout=30" -) - func init() { filer.Stores = append(filer.Stores, &PostgresStore{}) } @@ -56,7 +53,16 @@ func (store *PostgresStore) initialize(upsertQuery string, enableUpsert bool, us UpsertQueryTemplate: upsertQuery, } - sqlUrl := fmt.Sprintf(CONNECTION_URL_PATTERN, hostname, port, sslmode) + sqlUrl := "connect_timeout=30" + if hostname != "" { + sqlUrl += " host=" + hostname + } + if port != 0 { + sqlUrl += " port=" + strconv.Itoa(port) + } + if sslmode != "" { + sqlUrl += " sslmode=" + sslmode + } if user != "" { sqlUrl += " user=" + user } |
