-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.go
executable file
·50 lines (43 loc) · 1.13 KB
/
db.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
// import (
// "database/sql"
// "encoding/json"
// "fmt"
// "io/ioutil"
// "log"
// // _ "github.com/denisenkom/go-mssqldb"
// _ "./odbc"
// )
// var db *sql.DB
// func Connect(source string) {
// b, _ := ioutil.ReadFile(source)
// var config map[string]interface{}
// if err := json.Unmarshal(b, &config); err != nil {
// panic(err)
// }
// connString := fmt.Sprintf(
// "Dsn=%s;Driver={%s};uid=%s;pwd=%s;database=%s;host=%s;srvr=%s;serv=%s;pro=%s;cloc=%s;dloc=%s;opt=%s;",
// config["dsn"],
// config["driver-name"],
// config["user"],
// config["password"],
// config["database"],
// config["host"],
// config["server"],
// config["services"],
// config["protocol"],
// config["cloc"],
// config["dloc"],
// config["opt"],
// )
// db, err := sql.Open(config["driver-type"].(string), connString)
// if err != nil {
// log.Panic("Open connection failed:", err.Error())
// }
// // defer db.Close()
// if err = db.Ping(); err != nil {
// log.Panic(err)
// } else {
// fmt.Println("Successfully connected to the database")
// }
// }