Guest User

Untitled

a guest
Mar 24th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "database/sql"
  5. "fmt"
  6.  
  7. _ "github.com/lib/pq"
  8. )
  9.  
  10. const (
  11. host = "your-host"
  12. port = 5432
  13. user = "your-user"
  14. password = "your-password"
  15. dbname = "your-db-name"
  16. )
  17.  
  18. func main() {
  19. psqlInfo := fmt.Sprintf("host=%s port=%d user=%s "+
  20. "password=%s dbname=%s sslmode=disable",
  21. host, port, user, password, dbname)
  22.  
  23. db, err := sql.Open("postgres", psqlInfo)
  24.  
  25. if err != nil {
  26. panic(err)
  27. }
  28.  
  29. defer db.Close()
  30.  
  31. err = db.Ping()
  32. if err != nil {
  33. panic(err)
  34. }
  35.  
  36. fmt.Println("Successfully connected!")
  37. }
Add Comment
Please, Sign In to add comment