Browse Source

Organizando pacotes

William Wiechorek 6 years ago
parent
commit
0610cbf7e5
6 changed files with 18 additions and 15 deletions
  1. BIN
      build
  2. 5 1
      src/lib/errors/errors.go
  3. 1 1
      core/request/request.go
  4. 3 4
      main.go
  5. 3 3
      routes/routes.go
  6. 6 6
      src/controller/Test/Test.go

BIN
build


+ 5 - 1
src/lib/errors/errors.go

@@ -56,5 +56,9 @@ func NotFound(message string) {
56 56
 }
57 57
 
58 58
 func Has() bool {
59
-	return len(errors) <= 0
59
+	return len(errors) > 0
60
+}
61
+
62
+func Get() []interface{} {
63
+	return errors
60 64
 }

+ 1 - 1
core/request/request.go

@@ -1,4 +1,4 @@
1
-package response
1
+package request
2 2
 
3 3
 import (
4 4
 	"fmt"

+ 3 - 4
main.go

@@ -7,10 +7,9 @@ import (
7 7
 
8 8
 	"./config"
9 9
 	"./core/database"
10
+	"./core/errors"
10 11
 	req "./core/request"
11 12
 	res "./core/response"
12
-	"./routes"
13
-	"./src/lib/errors"
14 13
 )
15 14
 
16 15
 func main() {
@@ -31,11 +30,11 @@ func main() {
31 30
 
32 31
 		if !database.IsConnected {
33 32
 			errors.InternalError("Conexão com a base de dados falhou!")
34
-			res.JSON(errors)
33
+			res.JSON(errors.Get())
35 34
 			return
36 35
 		}
37 36
 
38
-		routes.Routes.Match(w, r)
37
+		Routes.Match(w, r)
39 38
 	})
40 39
 
41 40
 	log.Fatal(http.ListenAndServe(":"+strconv.Itoa(config.SERVER_PORT), nil))

+ 3 - 3
routes/routes.go

@@ -1,8 +1,8 @@
1
-package routes
1
+package main
2 2
 
3 3
 import (
4
-	"../core/router"
5
-	"../src/controller/test"
4
+	"./core/router"
5
+	"./src/controller/test"
6 6
 )
7 7
 
8 8
 //Routes rotas de acesso

+ 6 - 6
src/controller/Test/Test.go

@@ -4,11 +4,11 @@ import (
4 4
 	"fmt"
5 5
 	"net/http"
6 6
 
7
-	req "../../../core/request"
8
-	res "../../../core/response"
7
+	"../../../core/errors"
8
+	"../../../core/request"
9
+	"../../../core/response"
9 10
 
10 11
 	auth "../../lib/auth"
11
-	"../../lib/errors"
12 12
 )
13 13
 
14 14
 type Profile struct {
@@ -38,12 +38,12 @@ func Inicial(w http.ResponseWriter, r *http.Request, vars []string) {
38 38
 	errors.InternalError("Ocorreu um erro interno")
39 39
 	errors.ActionForbidden("Ocorreu um erro interno2")
40 40
 
41
-	if !errors.Has() {
42
-		res.JSON(errors)
41
+	if errors.Has() {
42
+		response.JSON(errors.Get())
43 43
 		return
44 44
 	}
45 45
 
46
-	fmt.Println(req.Method())
46
+	fmt.Println(request.Method())
47 47
 
48 48
 	// res.SetCode(404)
49 49
 	// res.JSON(profile)