2
我試圖連接到我的本地PostgreSQL服務器沒有SSL,我得到這個錯誤:轉到Postgres的連接SSL
pq: SSL is not enabled on the server
這很好,我知道如何解決它:
type App struct {
Router *mux.Router
DB *sql.DB
}
func (a *App) Initialize(dbname string) {
connectionString := fmt.Sprintf("dbname=%s sslmode=disable", dbname)
var err error
a.DB, err = sql.Open("postgres", connectionString)
if err != nil {
log.Fatal(err)
}
defer a.DB.Close()
}
但是我仍然收到錯誤!
還有其他的語法來連接到使用golang的postgres數據庫,你有沒有嘗試過其他方式? – zenwraight
@zenwraight是的,我結束了與URL字符串版本去獲取最初的東西的工作,但我需要能夠更改數據庫名稱,以測試'a.DB,err = sql.Open(「 postgres「,」postgresql:// localhost:5432/bookstore?sslmode = disable「)' – Godzilla74
雅我只是建議這一個,因爲我也遇到了同樣的錯誤,然後結束了使用這個上面的字符串只有 – zenwraight