-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathdebug.go
186 lines (160 loc) · 6.9 KB
/
debug.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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
package main
import (
"log"
"net/http"
"github.com/TibiaData/tibiadata-api-go/src/validation"
"github.com/gin-gonic/gin"
"github.com/go-resty/resty/v2"
)
// Debug stores some debug informations
type Debug struct {
TibiaDataUserAgent string `json:"tibia_data_user_agent"`
DataSha256Sum string `json:"data_sha_256_sum"`
DataSha512Sum string `json:"data_sha_512_sum"`
SmallestCreatureName string `json:"smallest_creature_name"`
BiggestCreatureName string `json:"biggest_creature_name"`
SmallestCreatureWord string `json:"smallest_creature_word"`
BiggestCreatureWord string `json:"biggest_creature_word"`
SmallestCreatureNameRuneCount int `json:"smallest_creature_name_rune_count"`
BiggestCreatureNameRuneCount int `json:"biggest_creature_name_rune_count"`
SmallestCreatureWordRuneCount int `json:"smallest_creature_word_rune_count"`
BiggestCreatureWordRuneCount int `json:"biggest_creature_word_rune_count"`
SmallestSpellNameOrFormula string `json:"smallest_spell_name_or_formula"`
BiggestSpellNameOrFormula string `json:"biggest_spell_name_or_formula"`
SmallestSpellWord string `json:"smallest_spell_word"`
BiggestSpellWord string `json:"biggest_spell_word"`
SmallestSpellNameOrFormulaRuneCount int `json:"smallest_spell_name_or_formula_rune_count"`
BiggestSpellNameOrFormulaRuneCount int `json:"biggest_spell_name_or_formula_rune_count"`
SmallestSpellWordRuneCount int `json:"smallest_spell_word_rune_count"`
BiggestSpellWordRuneCount int `json:"biggest_spell_word_rune_count"`
}
// TibiaDataRequestTraceLogger func - prints out trace information to log
func TibiaDataRequestTraceLogger(res *resty.Response, err error) {
log.Println("TRACE RESTY",
"\n~~~ TRACE INFO ~~~",
"\nDNSLookup :", res.Request.TraceInfo().DNSLookup,
"\nConnTime :", res.Request.TraceInfo().ConnTime,
"\nTCPConnTime :", res.Request.TraceInfo().TCPConnTime,
"\nTLSHandshake :", res.Request.TraceInfo().TLSHandshake,
"\nServerTime :", res.Request.TraceInfo().ServerTime,
"\nResponseTime :", res.Request.TraceInfo().ResponseTime,
"\nTotalTime :", res.Request.TraceInfo().TotalTime,
"\nIsConnReused :", res.Request.TraceInfo().IsConnReused,
"\nIsConnWasIdle :", res.Request.TraceInfo().IsConnWasIdle,
"\nConnIdleTime :", res.Request.TraceInfo().ConnIdleTime,
"\nRequestAttempt :", res.Request.TraceInfo().RequestAttempt,
"\nRemoteAddr :", res.Request.TraceInfo().RemoteAddr.String(),
"\nError :", err,
"\n==============================================================================")
}
// debugHandler returns some debug information
func debugHandler(c *gin.Context) {
data := Information{
APIDetails: TibiaDataAPIDetails,
Timestamp: TibiaDataDatetime(""),
Status: Status{
HTTPCode: http.StatusOK,
Message: "UP",
},
}
debug := Debug{
TibiaDataUserAgent: TibiaDataUserAgent,
}
// Shas
sha256, err := validation.GetSha256Sum()
if err != nil {
TibiaDataErrorHandler(c, err, http.StatusInternalServerError)
}
debug.DataSha256Sum = sha256
sha512, err := validation.GetSha512Sum()
if err != nil {
TibiaDataErrorHandler(c, err, http.StatusInternalServerError)
}
debug.DataSha512Sum = sha512
// Creatures
smallestCreatureName, err := validation.GetSmallestCreatureName()
if err != nil {
TibiaDataErrorHandler(c, err, http.StatusInternalServerError)
}
debug.SmallestCreatureName = smallestCreatureName
biggestCreatureName, err := validation.GetBiggestCreatureName()
if err != nil {
TibiaDataErrorHandler(c, err, http.StatusInternalServerError)
}
debug.BiggestCreatureName = biggestCreatureName
biggestCreatureWord, err := validation.GetBiggestCreatureWord()
if err != nil {
TibiaDataErrorHandler(c, err, http.StatusInternalServerError)
}
debug.BiggestCreatureWord = biggestCreatureWord
smallestCreatureWord, err := validation.GetSmallestCreatureWord()
if err != nil {
TibiaDataErrorHandler(c, err, http.StatusInternalServerError)
}
debug.SmallestCreatureWord = smallestCreatureWord
smallestCreatureNameRuneCount, err := validation.GetSmallestCreatureNameRuneCount()
if err != nil {
TibiaDataErrorHandler(c, err, http.StatusInternalServerError)
}
debug.SmallestCreatureNameRuneCount = smallestCreatureNameRuneCount
biggestCreatureNameRuneCount, err := validation.GetBiggestCreatureNameRuneCount()
if err != nil {
TibiaDataErrorHandler(c, err, http.StatusInternalServerError)
}
debug.BiggestCreatureNameRuneCount = biggestCreatureNameRuneCount
smallestCreatureWordRuneCount, err := validation.GetSmallestCreatureWordRuneCount()
if err != nil {
TibiaDataErrorHandler(c, err, http.StatusInternalServerError)
}
debug.SmallestCreatureWordRuneCount = smallestCreatureWordRuneCount
biggestCreatureWordRuneCount, err := validation.GetBiggestCreatureWordRuneCount()
if err != nil {
TibiaDataErrorHandler(c, err, http.StatusInternalServerError)
}
debug.BiggestCreatureWordRuneCount = biggestCreatureWordRuneCount
// Spells
smallestSpellName, err := validation.GetSmallestSpellNameOrFormula()
if err != nil {
TibiaDataErrorHandler(c, err, http.StatusInternalServerError)
}
debug.SmallestSpellNameOrFormula = smallestSpellName
biggestSpellName, err := validation.GetBiggestSpellNameOrFormula()
if err != nil {
TibiaDataErrorHandler(c, err, http.StatusInternalServerError)
}
debug.BiggestSpellNameOrFormula = biggestSpellName
biggestSpellWord, err := validation.GetBiggestSpellWord()
if err != nil {
TibiaDataErrorHandler(c, err, http.StatusInternalServerError)
}
debug.BiggestSpellWord = biggestSpellWord
smallestSpellWord, err := validation.GetSmallestSpellWord()
if err != nil {
TibiaDataErrorHandler(c, err, http.StatusInternalServerError)
}
debug.SmallestSpellWord = smallestSpellWord
smallestSpellNameRuneCount, err := validation.GetSmallestSpellNameOrFormulaRuneCount()
if err != nil {
TibiaDataErrorHandler(c, err, http.StatusInternalServerError)
}
debug.SmallestSpellNameOrFormulaRuneCount = smallestSpellNameRuneCount
biggestSpellNameRuneCount, err := validation.GetBiggestSpellNameOrFormulaRuneCount()
if err != nil {
TibiaDataErrorHandler(c, err, http.StatusInternalServerError)
}
debug.BiggestSpellNameOrFormulaRuneCount = biggestSpellNameRuneCount
smallestSpellWordRuneCount, err := validation.GetSmallestSpellWordRuneCount()
if err != nil {
TibiaDataErrorHandler(c, err, http.StatusInternalServerError)
}
debug.SmallestSpellWordRuneCount = smallestSpellWordRuneCount
biggestSpellWordRuneCount, err := validation.GetBiggestSpellWordRuneCount()
if err != nil {
TibiaDataErrorHandler(c, err, http.StatusInternalServerError)
}
debug.BiggestSpellWordRuneCount = biggestSpellWordRuneCount
var output DebugOutInformation
output.Information = data
output.Debug = debug
c.JSON(http.StatusOK, output)
}