Nav apraksta

database.go 317B

12345678910111213141516171819202122232425262728
  1. package database
  2. import (
  3. "database/sql"
  4. "log"
  5. _ "github.com/go-sql-driver/mysql"
  6. )
  7. var DB *sql.DB
  8. func Init(dataSourceName string) error {
  9. var err error
  10. DB, err = sql.Open("mysql", dataSourceName)
  11. if err != nil {
  12. log.Panic(err)
  13. }
  14. if err = DB.Ping(); err != nil {
  15. log.Panic(err)
  16. }
  17. return err
  18. }