|
@@ -1,23 +1,31 @@
|
1
|
|
-package lib
|
|
1
|
+package auth
|
2
|
2
|
|
3
|
3
|
import (
|
4
|
4
|
"encoding/json"
|
|
5
|
+ "errors"
|
5
|
6
|
"log"
|
6
|
7
|
"net/http"
|
7
|
|
- "errors"
|
8
|
|
- "../curl"
|
|
8
|
+
|
9
|
9
|
"../../config"
|
|
10
|
+ "../curl"
|
10
|
11
|
)
|
11
|
12
|
|
12
|
13
|
type UserData struct {
|
13
|
|
- UserId int `json:"id_user"`
|
14
|
|
- Email string `json:"email"`
|
15
|
|
- Name string `json:"name"`
|
16
|
|
- Username string `json:"username"`
|
17
|
|
- Token string `json:"token"`
|
18
|
|
- UrlToken string `json:"url_token"`
|
19
|
|
- Avatar string `json:"avatar"`
|
20
|
|
- Language string `json:"language"`
|
|
14
|
+ UserId int `json:"id_user"`
|
|
15
|
+ Email string `json:"email"`
|
|
16
|
+ Name string `json:"name"`
|
|
17
|
+ Username string `json:"username"`
|
|
18
|
+ Token string `json:"token"`
|
|
19
|
+ UrlToken string `json:"url_token"`
|
|
20
|
+ Avatar string `json:"avatar"`
|
|
21
|
+ Language string `json:"language"`
|
|
22
|
+ Errors []apiError `json:"errors"`
|
|
23
|
+}
|
|
24
|
+
|
|
25
|
+type apiError struct {
|
|
26
|
+ Type string `json:"type"`
|
|
27
|
+ Parameter string `json:"parameter"`
|
|
28
|
+ Message string `json:"message"`
|
21
|
29
|
}
|
22
|
30
|
|
23
|
31
|
// func (user UserData) getId() int {
|
|
@@ -33,7 +41,12 @@ func GetUser(httpReq *http.Request) (*UserData, bool) {
|
33
|
41
|
return nil, false
|
34
|
42
|
}
|
35
|
43
|
|
36
|
|
- response := curl.Curl(curlReq)
|
|
44
|
+ response, err := curl.Curl(curlReq)
|
|
45
|
+
|
|
46
|
+ if err != nil {
|
|
47
|
+ log.Print(err)
|
|
48
|
+ return nil, false
|
|
49
|
+ }
|
37
|
50
|
|
38
|
51
|
var userData UserData
|
39
|
52
|
|
|
@@ -53,19 +66,20 @@ func GetUser(httpReq *http.Request) (*UserData, bool) {
|
53
|
66
|
return &userData, true
|
54
|
67
|
}
|
55
|
68
|
|
56
|
|
-func curlRequest(request *http.Request) curl.Request, error {
|
|
69
|
+func curlRequest(request *http.Request) (*curl.Request, error) {
|
57
|
70
|
|
58
|
71
|
authToken := request.Header.Get("Auth")
|
59
|
72
|
|
60
|
|
- if authToken != nil {
|
|
73
|
+ if authToken != "" {
|
|
74
|
+
|
|
75
|
+ headers := make(map[string]string)
|
61
|
76
|
|
62
|
|
- headers map[string]string
|
63
|
77
|
headers["Auth"] = authToken
|
64
|
|
-
|
65
|
|
- curlReq := curl.Request{
|
66
|
|
- Url: config.AUTHENTICATION_SERVICE
|
67
|
|
- Method: "POST"
|
68
|
|
- Headers: headers
|
|
78
|
+
|
|
79
|
+ curlReq := &curl.Request{
|
|
80
|
+ Url: config.AUTHENTICATION_SERVICE,
|
|
81
|
+ Method: "POST",
|
|
82
|
+ Headers: headers,
|
69
|
83
|
}
|
70
|
84
|
|
71
|
85
|
return curlReq, nil
|