增加请求方法的获取

This commit is contained in:
白茶清欢 2024-01-02 15:20:08 +08:00
parent d94d4b0e9f
commit 3298adb55a
1 changed files with 18 additions and 5 deletions

View File

@ -61,6 +61,18 @@ func (wh *wrapperHandle) GetUri(ctx *gin.Context, defaultVal string) string {
return defaultVal
}
// GetMethod 获取请求方法
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 15:19 2024/1/2
func (wh *wrapperHandle) GetMethod(ctx *gin.Context) string {
if nil != ctx && nil != ctx.Request {
return ctx.Request.Method
}
return ""
}
// GetContentType 获取请求方式
//
// Author : go_developer@163.com<白茶清欢>
@ -74,10 +86,11 @@ func (wh *wrapperHandle) GetContentType(ctx *gin.Context, defaultVal string) str
return wrapper.TernaryOperator.String(len(contentType) > 0, wrapper.String(contentType), wrapper.String(defaultVal)).Value()
}
// GetResponseBody 获取响应body
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 15:18 2024/1/2
func (wh *wrapperHandle) GetResponseBody(ctx *gin.Context, defaultVal string) string {
if nil == ctx {
return defaultVal
}
contentType := strings.ToLower(ctx.ContentType())
return wrapper.TernaryOperator.String(len(contentType) > 0, wrapper.String(contentType), wrapper.String(defaultVal)).Value()
return ""
}