-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresponse_warning.go
46 lines (38 loc) · 1.15 KB
/
response_warning.go
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
package api
import (
"net/http"
"github.com/jgolang/api/core"
)
var (
// DefaultWarningTitle default warning title.
DefaultWarningTitle = "Alert!"
// DefaultWarningMessage default warning message.
DefaultWarningMessage = "The application has been successful but with potential problems!"
// WarningType warning response type the value is "warning"
WarningType core.ResponseType = "warning"
// DefaultWarningCode default warning code.
DefaultWarningCode = "0000"
)
// Warning warning response type the value is "warning".
type Warning core.ResponseData
// Write warning response in screen.
func (warning Warning) Write(w http.ResponseWriter, r *http.Request) {
warning.EventID = getEventID(r)
warning.ResponseType = WarningType
if warning.Title == "" {
warning.Title = DefaultWarningTitle
}
if warning.Message == "" {
warning.Message = DefaultWarningMessage
}
if warning.HTTPStatusCode == 0 {
warning.HTTPStatusCode = http.StatusContinue
}
if warning.ResponseCode == "" {
warning.ResponseCode = ResponseCodes.Warning
}
if warning.SecurityToken == "" {
warning.SecurityToken = getSecurityToken(r)
}
api.Write(core.ResponseData(warning), w)
}