MCPcopy Index your code
hub / github.com/writefreely/writefreely / initMySQL

Function initMySQL

main_test.go:50–70  ·  view source on GitHub ↗
(dbUser, dbPassword, dbName, dbHost string)

Source from the content-addressed store, hash-verified

48}
49
50func initMySQL(dbUser, dbPassword, dbName, dbHost string) (*sql.DB, error) {
51 if dbUser == "" || dbPassword == "" {
52 return nil, errors.New("database user or password not set")
53 }
54 if dbHost == "" {
55 dbHost = "localhost"
56 }
57 if dbName == "" {
58 dbName = "writefreely"
59 }
60
61 dsn := fmt.Sprintf("%s:%s@tcp(%s:3306)/%s?charset=utf8mb4&parseTime=true", dbUser, dbPassword, dbHost, dbName)
62 db, err := sql.Open("mysql", dsn)
63 if err != nil {
64 return nil, err
65 }
66 if err := ensureMySQL(db); err != nil {
67 return nil, err
68 }
69 return db, nil
70}
71
72func ensureMySQL(db *sql.DB) error {
73 if err := db.Ping(); err != nil {

Callers 2

TestMainFunction · 0.85
newTestDatabaseFunction · 0.85

Calls 1

ensureMySQLFunction · 0.85

Tested by

no test coverage detected