Skip to content

Commit 7e1ca42

Browse files
committed
#### Version 1.3.2
* 主要新增设置启用详细请求数据控制,新增MethodNotAllowedHandler自定义能力,完善数据统计逻辑 * 新增设置启用详细请求数据控制: * 1) ServerStateInfo增加EnabledDetailRequestData,用于控制是否启用详细请求数据统计 * 2) config.ServerConfig增加EnabledDetailRequestData设置,支持配置文件控制 * 3) HttpServer增加SetEnabledDetailRequestData函数,用于代码设置是否启用详细请求数据统计 * 4) fixed devfeel#63 状态数据,当url较多时,导致内存占用过大 * 新增MethodNotAllowedHandler自定义能力 * 1) dotweb增加DefaultMethodNotAllowedHandler、SetMethodNotAllowedHandle函数 * 2) fixed devfeel#64 增加MethodNotAllowed自定义处理 * 完善数据统计逻辑 * 1) 404请求不计入详细请求数据统计 * 2017-10-13 12:00
1 parent a3bd4a1 commit 7e1ca42

3 files changed

Lines changed: 14 additions & 12 deletions

File tree

‎core/state.go‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,21 +64,21 @@ type pool struct {
6464

6565
//http request count info
6666
type RequestInfo struct {
67-
Url string
67+
URL string
6868
Code int
6969
Num uint64
7070
}
7171

7272
//error count info
7373
type ErrorInfo struct {
74-
Url string
74+
URL string
7575
ErrMsg string
7676
Num uint64
7777
}
7878

7979
//httpcode count info
8080
type HttpCodeInfo struct {
81-
Url string
81+
URL string
8282
Code int
8383
Num uint64
8484
}
@@ -179,7 +179,7 @@ func (state *ServerStateInfo) AddErrorCount(page string, err error, num uint64)
179179
func (state *ServerStateInfo) addRequestData(page string, code int, num uint64) {
180180
//get from pool
181181
info := state.infoPool.requestInfo.Get().(*RequestInfo)
182-
info.Url = page
182+
info.URL = page
183183
info.Code = code
184184
info.Num = num
185185
state.dataChan_Request <- info
@@ -188,7 +188,7 @@ func (state *ServerStateInfo) addRequestData(page string, code int, num uint64)
188188
func (state *ServerStateInfo) addErrorData(page string, err error, num uint64) {
189189
//get from pool
190190
info := state.infoPool.errorInfo.Get().(*ErrorInfo)
191-
info.Url = page
191+
info.URL = page
192192
info.ErrMsg = err.Error()
193193
info.Num = num
194194
state.dataChan_Error <- info
@@ -197,7 +197,7 @@ func (state *ServerStateInfo) addErrorData(page string, err error, num uint64) {
197197
func (state *ServerStateInfo) addHTTPCodeData(page string, code int, num uint64) {
198198
//get from pool
199199
info := state.infoPool.httpCodeInfo.Get().(*HttpCodeInfo)
200-
info.Url = page
200+
info.URL = page
201201
info.Code = code
202202
info.Num = num
203203
state.dataChan_HttpCode <- info
@@ -214,7 +214,7 @@ func (state *ServerStateInfo) handleInfo() {
214214
//ignore 404 request
215215
if info.Code != http.StatusNotFound {
216216
//set detail url data
217-
key := strings.ToLower(info.Url)
217+
key := strings.ToLower(info.URL)
218218
val := state.DetailRequestUrlData.GetUInt64(key)
219219
state.DetailRequestUrlData.Set(key, val+info.Num)
220220
}
@@ -230,7 +230,7 @@ func (state *ServerStateInfo) handleInfo() {
230230
case info := <-state.dataChan_Error:
231231
{
232232
//set detail error page data
233-
key := strings.ToLower(info.Url)
233+
key := strings.ToLower(info.URL)
234234
val := state.DetailErrorPageData.GetUInt64(key)
235235
state.DetailErrorPageData.Set(key, val+info.Num)
236236

‎dotweb.go‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@ type (
3737
middlewareMutex *sync.RWMutex
3838
}
3939

40+
// ExceptionHandle 支持自定义异常处理代码能力
4041
ExceptionHandle func(Context, error)
41-
//fixed for #64 增加MethodNotAllowed自定义处理
42+
// MethodNotAllowedHandle fixed for #64 增加MethodNotAllowed自定义处理
4243
MethodNotAllowedHandle func(Context)
43-
NotFoundHandle func(Context)
44+
// NotFoundHandle 支持自定义404处理代码能力
45+
NotFoundHandle func(Context)
4446

4547
// Handle is a function that can be registered to a route to handle HTTP
4648
// requests. Like http.HandlerFunc, but has a special parameter Context contain all request and response data.
@@ -414,7 +416,7 @@ func (app *DotWeb) DefaultNotFoundHandler(ctx Context) {
414416
ctx.WriteStringC(http.StatusNotFound, http.StatusText(http.StatusNotFound))
415417
}
416418

417-
// DefaultNotFoundHandler default exception handler
419+
// DefaultMethodNotAllowedHandler default exception handler
418420
func (app *DotWeb) DefaultMethodNotAllowedHandler(ctx Context) {
419421
ctx.Response().Header().Set(HeaderContentType, CharsetUTF8)
420422
ctx.WriteStringC(http.StatusMethodNotAllowed, http.StatusText(http.StatusMethodNotAllowed))

‎server.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ func (server *HttpServer) SetEnabledTLS(isEnabled bool, certFile, keyFile string
368368
logger.Logger().Debug("DotWeb:HttpServer SetEnabledTLS ["+strconv.FormatBool(isEnabled)+","+certFile+","+keyFile+"]", LogTarget_HttpServer)
369369
}
370370

371-
// EnabledDetailRequestData 设置是否启用详细请求数据统计,默认为false
371+
// SetEnabledDetailRequestData 设置是否启用详细请求数据统计,默认为false
372372
func (server *HttpServer) SetEnabledDetailRequestData(isEnabled bool) {
373373
server.ServerConfig().EnabledDetailRequestData = isEnabled
374374
logger.Logger().Debug("DotWeb:HttpServer SetEnabledDetailRequestData ["+strconv.FormatBool(isEnabled)+"]", LogTarget_HttpServer)

0 commit comments

Comments
 (0)