123456789101112131415161718192021222324252627282930313233343536 |
- package database
- import (
- "database/sql"
- "log"
- "../../config"
- _ "github.com/go-sql-driver/mysql"
- )
- var DB *sql.DB
- func Init() error {
- //user:pass@tcp(host:port)/schema?parseTime=true
- var dataSource = config.DATABASE_USER + ":" +
- config.DATABASE_PASS + "@tcp(" +
- config.DATABASE_HOST + ":" +
- config.DATABASE_PORT + ")/" +
- config.DATABASE_SCHEMA + "?parseTime=true"
- var err error
- DB, err = sql.Open("mysql", dataSource)
- if err != nil {
- log.Panic(err)
- }
- if err = DB.Ping(); err != nil {
- log.Panic(err)
- }
- return err
- }
|