William Wiechorek 6 years ago
parent
commit
7f4543392d
4 changed files with 18 additions and 4 deletions
  1. BIN
      build
  2. 1 1
      config/config.go
  3. 7 3
      core/database/database.go
  4. 10 0
      main.go

BIN
build


+ 1 - 1
config/config.go

7
 const DATABASE_HOST = "208.97.141.22"
7
 const DATABASE_HOST = "208.97.141.22"
8
 const DATABASE_PORT = "3306"
8
 const DATABASE_PORT = "3306"
9
 const DATABASE_USER = "hml"
9
 const DATABASE_USER = "hml"
10
-const DATABASE_PASS = "spr777hml"
10
+const DATABASE_PASS = "spr7772hml"
11
 const DATABASE_SCHEMA = "hml_mkt_sprinta"
11
 const DATABASE_SCHEMA = "hml_mkt_sprinta"
12
 
12
 
13
 /* SERVICES ENDPOINTS */
13
 /* SERVICES ENDPOINTS */

+ 7 - 3
core/database/database.go

2
 
2
 
3
 import (
3
 import (
4
 	"database/sql"
4
 	"database/sql"
5
-	"log"
6
 
5
 
7
 	_ "github.com/go-sql-driver/mysql"
6
 	_ "github.com/go-sql-driver/mysql"
8
 )
7
 )
19
 	Schema string
18
 	Schema string
20
 }
19
 }
21
 
20
 
21
+var IsConnected bool
22
+var Error error
23
+
22
 //Init : iniciação do metodo de conexão
24
 //Init : iniciação do metodo de conexão
23
 func Init(config Config) error {
25
 func Init(config Config) error {
24
 
26
 
34
 	DB, err = sql.Open("mysql", dataSource)
36
 	DB, err = sql.Open("mysql", dataSource)
35
 
37
 
36
 	if err != nil {
38
 	if err != nil {
37
-		log.Panic(err)
39
+		IsConnected = false
40
+		Error = err
38
 	}
41
 	}
39
 
42
 
40
 	if err = DB.Ping(); err != nil {
43
 	if err = DB.Ping(); err != nil {
41
-		log.Panic(err)
44
+		IsConnected = false
45
+		Error = err
42
 	}
46
 	}
43
 
47
 
44
 	return err
48
 	return err

+ 10 - 0
main.go

10
 	req "./core/request"
10
 	req "./core/request"
11
 	res "./core/response"
11
 	res "./core/response"
12
 	"./routes"
12
 	"./routes"
13
+	errorHandler "./src/lib/error"
13
 )
14
 )
14
 
15
 
15
 func main() {
16
 func main() {
24
 	database.Init(dbConfig)
25
 	database.Init(dbConfig)
25
 
26
 
26
 	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
27
 	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
28
+		var Errors errorHandler.Errors
29
+
27
 		res.SetResponseWriter(w)
30
 		res.SetResponseWriter(w)
28
 		req.SetRequest(r)
31
 		req.SetRequest(r)
32
+
33
+		if !database.IsConnected {
34
+			Errors.InternalError("Conexão com a base de dados falhou!")
35
+			res.JSON(Errors)
36
+			return
37
+		}
38
+
29
 		routes.Routes.Match(w, r)
39
 		routes.Routes.Match(w, r)
30
 	})
40
 	})
31
 
41