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

@@ -56,12 +56,16 @@ func New(config ...Config) *Storage {
if cfg.Username != "" || cfg.Password != "" {
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",
url.QueryEscape(cfg.Database),
int64(cfg.timeout.Seconds()),
cfg.SslMode,
)
cfg.SslMode)
// Create db
db, err := sql.Open("postgres", dsn)