|
@@ -4,20 +4,30 @@ import (
|
4
|
4
|
"database/sql"
|
5
|
5
|
"log"
|
6
|
6
|
|
7
|
|
- "../../config"
|
8
|
7
|
_ "github.com/go-sql-driver/mysql"
|
9
|
8
|
)
|
10
|
9
|
|
|
10
|
+//DB : Conexão com db
|
11
|
11
|
var DB *sql.DB
|
12
|
12
|
|
13
|
|
-func Init() error {
|
|
13
|
+//Config : struct do banco de dados
|
|
14
|
+type Config struct {
|
|
15
|
+ Host string
|
|
16
|
+ Port string
|
|
17
|
+ User string
|
|
18
|
+ Pass string
|
|
19
|
+ Schema string
|
|
20
|
+}
|
|
21
|
+
|
|
22
|
+//Init : iniciação do metodo de conexão
|
|
23
|
+func Init(config Config) error {
|
14
|
24
|
|
15
|
25
|
//user:pass@tcp(host:port)/schema?parseTime=true
|
16
|
|
- var dataSource = config.DATABASE_USER + ":" +
|
17
|
|
- config.DATABASE_PASS + "@tcp(" +
|
18
|
|
- config.DATABASE_HOST + ":" +
|
19
|
|
- config.DATABASE_PORT + ")/" +
|
20
|
|
- config.DATABASE_SCHEMA + "?parseTime=true"
|
|
26
|
+ var dataSource = config.User + ":" +
|
|
27
|
+ config.Pass + "@tcp(" +
|
|
28
|
+ config.Host + ":" +
|
|
29
|
+ config.Port + ")/" +
|
|
30
|
+ config.Schema + "?parseTime=true"
|
21
|
31
|
|
22
|
32
|
var err error
|
23
|
33
|
|