allow hosts with prefix "/" , without escaping (#363)

* allow hosts with prefix "/" , without escaping

* add comment and fix code style

* fix bug

* Remove duplicate format call

* Update lib/pq

* try to fix goSec setup error

Co-authored-by: RW <rene@gofiber.io>
Co-authored-by: hi019 <65871571+hi019@users.noreply.github.com>
This commit is contained in:
Infinite Sea Inc
2022-05-01 03:07:09 -06:00
committed by GitHub
parent bd65618ff5
commit b2e9530bc7
3 changed files with 10 additions and 4 deletions

View File

@@ -4,5 +4,5 @@ go 1.14
require ( require (
github.com/gofiber/utils v0.1.2 github.com/gofiber/utils v0.1.2
github.com/lib/pq v1.10.4 github.com/lib/pq v1.10.5
) )

View File

@@ -2,3 +2,5 @@ github.com/gofiber/utils v0.1.2 h1:1SH2YEz4RlNS0tJlMJ0bGwO0JkqPqvq6TbHK9tXZKtk=
github.com/gofiber/utils v0.1.2/go.mod h1:pacRFtghAE3UoknMOUiXh2Io/nLWSUHtQCi/3QASsOc= github.com/gofiber/utils v0.1.2/go.mod h1:pacRFtghAE3UoknMOUiXh2Io/nLWSUHtQCi/3QASsOc=
github.com/lib/pq v1.10.4 h1:SO9z7FRPzA03QhHKJrH5BXA6HU1rS4V2nIVrrNC1iYk= github.com/lib/pq v1.10.4 h1:SO9z7FRPzA03QhHKJrH5BXA6HU1rS4V2nIVrrNC1iYk=
github.com/lib/pq v1.10.4/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/lib/pq v1.10.4/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/lib/pq v1.10.5 h1:J+gdV2cUmX7ZqL2B0lFcW0m+egaHC2V3lpO8nWxyYiQ=
github.com/lib/pq v1.10.5/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=

View File

@@ -56,12 +56,16 @@ func New(config ...Config) *Storage {
if cfg.Username != "" || cfg.Password != "" { if cfg.Username != "" || cfg.Password != "" {
dsn += "@" dsn += "@"
} }
dsn += fmt.Sprintf("%s:%d", url.QueryEscape(cfg.Host), cfg.Port) // unix socket host path
if strings.HasPrefix(cfg.Host, "/") {
dsn += fmt.Sprintf("%s:%d", cfg.Host, cfg.Port)
} else {
dsn += fmt.Sprintf("%s:%d", url.QueryEscape(cfg.Host), cfg.Port)
}
dsn += fmt.Sprintf("/%s?connect_timeout=%d&sslmode=%s", dsn += fmt.Sprintf("/%s?connect_timeout=%d&sslmode=%s",
url.QueryEscape(cfg.Database), url.QueryEscape(cfg.Database),
int64(cfg.timeout.Seconds()), int64(cfg.timeout.Seconds()),
cfg.SslMode, cfg.SslMode)
)
// Create db // Create db
db, err := sql.Open("postgres", dsn) db, err := sql.Open("postgres", dsn)