mirror of
https://gitee.com/johng/gf
synced 2026-07-08 22:40:30 +08:00
chore: upgrade golangci-lint configuration and optimize codebase (#4236)
This PR includes the following changes: - **Upgrade `.golangci.yml`**: Updated the configuration file to align with the latest golangci-lint version, ensuring compatibility and leveraging new features. - **Refactor GitHub Action workflow**: Modified `golangci-lint.yml` in the GitHub Actions workflow to reflect the updated configuration and improve CI performance. - **Codebase optimization**: Refactored code to address issues and warnings raised by the updated golangci-lint rules, including: - Improved function length and complexity. - Enhanced error handling and variable naming conventions. - Fixed minor issues such as unused imports and formatting inconsistencies. These changes aim to maintain code quality, ensure compatibility with the latest tools, and improve overall maintainability.
This commit is contained in:
@ -371,7 +371,7 @@ func (c *Client) callRequest(req *http.Request) (resp *Response, err error) {
|
||||
err = gerror.Wrapf(err, `request failed`)
|
||||
// The response might not be nil when err != nil.
|
||||
if resp.Response != nil {
|
||||
_ = resp.Response.Body.Close()
|
||||
_ = resp.Body.Close()
|
||||
}
|
||||
if c.retryCount > 0 {
|
||||
c.retryCount--
|
||||
|
||||
@ -57,7 +57,7 @@ func (r *Response) ReadAll() []byte {
|
||||
if r == nil || r.Response == nil {
|
||||
return []byte{}
|
||||
}
|
||||
body, err := io.ReadAll(r.Response.Body)
|
||||
body, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
intlog.Errorf(r.request.Context(), `%+v`, err)
|
||||
return nil
|
||||
@ -82,5 +82,5 @@ func (r *Response) Close() error {
|
||||
if r == nil || r.Response == nil {
|
||||
return nil
|
||||
}
|
||||
return r.Response.Body.Close()
|
||||
return r.Body.Close()
|
||||
}
|
||||
|
||||
@ -184,7 +184,7 @@ func (r *Request) GetBodyString() string {
|
||||
// Note that the request content is read from request BODY, not from any field of FORM.
|
||||
func (r *Request) GetJson() (*gjson.Json, error) {
|
||||
return gjson.LoadWithOptions(r.GetBody(), gjson.Options{
|
||||
Type: gjson.ContentTypeJson,
|
||||
Type: gjson.ContentTypeJSON,
|
||||
StrNumber: true,
|
||||
})
|
||||
}
|
||||
|
||||
@ -31,7 +31,7 @@ func (r *Request) Context() context.Context {
|
||||
// Inject Request object into context.
|
||||
ctx = context.WithValue(ctx, ctxKeyForRequest, r)
|
||||
// Update the values of the original HTTP request.
|
||||
*r.Request = *r.Request.WithContext(ctx)
|
||||
*r.Request = *r.WithContext(ctx)
|
||||
}
|
||||
return ctx
|
||||
}
|
||||
@ -72,5 +72,5 @@ func (r *Request) GetCtxVar(key interface{}, def ...interface{}) *gvar.Var {
|
||||
func (r *Request) SetCtxVar(key interface{}, value interface{}) {
|
||||
var ctx = r.Context()
|
||||
ctx = context.WithValue(ctx, key, value)
|
||||
*r.Request = *r.Request.WithContext(ctx)
|
||||
*r.Request = *r.WithContext(ctx)
|
||||
}
|
||||
|
||||
@ -30,9 +30,9 @@ func (r *Response) Write(content ...interface{}) {
|
||||
case []byte:
|
||||
_, _ = r.BufferWriter.Write(value)
|
||||
case string:
|
||||
_, _ = r.BufferWriter.WriteString(value)
|
||||
_, _ = r.WriteString(value)
|
||||
default:
|
||||
_, _ = r.BufferWriter.WriteString(gconv.String(v))
|
||||
_, _ = r.WriteString(gconv.String(v))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -204,7 +204,7 @@ func (s *Server) handleAfterRequestDone(request *Request) {
|
||||
|
||||
// Close the request and response body
|
||||
// to release the file descriptor in time.
|
||||
err := request.Request.Body.Close()
|
||||
err := request.Body.Close()
|
||||
if err != nil {
|
||||
intlog.Errorf(request.Context(), `%+v`, err)
|
||||
}
|
||||
|
||||
@ -74,15 +74,15 @@ func (w *BufferWriter) WriteHeader(status int) {
|
||||
|
||||
// Flush outputs the buffer to clients and clears the buffer.
|
||||
func (w *BufferWriter) Flush() {
|
||||
if w.Writer.IsHijacked() {
|
||||
if w.IsHijacked() {
|
||||
return
|
||||
}
|
||||
|
||||
if w.Status != 0 && !w.Writer.IsHeaderWrote() {
|
||||
if w.Status != 0 && !w.IsHeaderWrote() {
|
||||
w.Writer.WriteHeader(w.Status)
|
||||
}
|
||||
// Default status text output.
|
||||
if w.Status != http.StatusOK && w.buffer.Len() == 0 && w.Writer.BytesWritten() == 0 {
|
||||
if w.Status != http.StatusOK && w.buffer.Len() == 0 && w.BytesWritten() == 0 {
|
||||
w.buffer.WriteString(http.StatusText(w.Status))
|
||||
}
|
||||
if w.buffer.Len() > 0 {
|
||||
|
||||
@ -16,11 +16,11 @@ import (
|
||||
|
||||
// IpToLongBigEndian converts ip address to an uint32 integer with big endian.
|
||||
func IpToLongBigEndian(ip string) uint32 {
|
||||
netIp := net.ParseIP(ip)
|
||||
if netIp == nil {
|
||||
netIP := net.ParseIP(ip)
|
||||
if netIP == nil {
|
||||
return 0
|
||||
}
|
||||
return binary.BigEndian.Uint32(netIp.To4())
|
||||
return binary.BigEndian.Uint32(netIP.To4())
|
||||
}
|
||||
|
||||
// LongToIpBigEndian converts an uint32 integer ip address to its string type address with big endian.
|
||||
|
||||
Reference in New Issue
Block a user