Repository navigation
Expand file tree
/
Copy pathbasic_request.go
More file actions
104 lines (93 loc) · 2.5 KB
/
Copy pathbasic_request.go
File metadata and controls
104 lines (93 loc) · 2.5 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package api
import (
"net/http"
)
// RequestBasic doc ...
type RequestBasic struct {
JSONStruct interface{}
SessionID string
UserID string
EventID string
HTTPReq *http.Request
}
// SecurityTokenHeaderKey session ID header key.
var SecurityTokenHeaderKey = "SecurityToken"
// UserIDHeaderKey User ID header key.
var UserIDHeaderKey = "UserID"
// EventIDHeaderKey event ID header key.
var EventIDHeaderKey = "EventID"
// GetSecurityToken gets security token from user by header key layout.
func (request *RequestBasic) GetSecurityToken() Response {
sessionID, response := GetHeaderValueString(SecurityTokenHeaderKey, request.HTTPReq)
if response != nil {
resp := response.(Error)
resp.Title = "Request info error!"
resp.Message = "The session id was not obtained"
return resp
}
request.SessionID = sessionID
return nil
}
// GetUserID gets id user ID by header key layout.
//
// The UserIDHeaderKey header is set by the client, so do not use it to
// identify or authorize the user.
func (request *RequestBasic) GetUserID() Response {
userID, response := GetHeaderValueString(UserIDHeaderKey, request.HTTPReq)
if response != nil {
resp := response.(Error)
resp.Title = "Request info error!"
resp.Message = "The user id was not obtained"
return resp
}
request.UserID = userID
return nil
}
// GetEventID gets event ID by header key layout.
func (request *RequestBasic) GetEventID() Response {
eventID, response := GetHeaderValueString(EventIDHeaderKey, request.HTTPReq)
if response != nil {
resp := response.(Error)
resp.Title = "Request info error!"
resp.Message = "The event id was not obtained"
return resp
}
request.EventID = eventID
return nil
}
// UnmarshalBody parses request body to a struct.
func (request *RequestBasic) UnmarshalBody() Response {
resp := UnmarshalBody(request.JSONStruct, request.HTTPReq)
if resp != nil {
return resp
}
return nil
}
// GetRequestBasicInfo gets session ID, user ID and event ID.
func (request *RequestBasic) GetRequestBasicInfo() Response {
resp := request.GetSecurityToken()
if resp != nil {
return resp
}
resp = request.GetUserID()
if resp != nil {
return resp
}
resp = request.GetEventID()
if resp != nil {
return resp
}
return nil
}
// GetRequestFullInfo gets session ID, userID, event ID and unmarshal request body.
func (request *RequestBasic) GetRequestFullInfo() Response {
resp := request.GetRequestBasicInfo()
if resp != nil {
return resp
}
resp = request.UnmarshalBody()
if resp != nil {
return resp
}
return nil
}