Created
February 27, 2018 02:49
-
-
Save aloha1003/c95b138ebae20ad8210bf412c07707c8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func init() { | |
revel.OnAppStart(InitDB) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func InitDB() { | |
host := getParamString("db.host", "") | |
port := getParamString("db.port", "3306") | |
user := getParamString("db.user", "") | |
pass := getParamString("db.password", "") | |
dbname := getParamString("db.name", "auction") | |
protocol := getParamString("db.protocol", "tcp") | |
dbargs := getParamString("dbargs", " ") | |
if strings.Trim(dbargs, " ") != "" { | |
dbargs = "?" + dbargs | |
} else { | |
dbargs = "" | |
} | |
connstring := fmt.Sprintf("%s:%s@%s(%s:%s)/%s%s",user, pass, protocol, host, port, dbname, dbargs) | |
var err error | |
DB, err = sql.Open("mysql", connstring) | |
revel.INFO.Println("DB Connected") | |
if err != nil { | |
revel.INFO.Println("DB Error", err) | |
} | |
revel.INFO.Println("DB Connected") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment