From ff8633231f9e919b8671b15330e18bd95bcc39e8 Mon Sep 17 00:00:00 2001 From: houseme Date: Tue, 16 Nov 2021 00:26:10 +0800 Subject: [PATCH] improve code 'if block ends with a return statement, so drop this else and outdent its block (golint)' --- container/garray/garray_normal_str.go | 3 +-- encoding/gurl/url.go | 8 ++++---- errors/gerror/gerror.go | 4 ++-- net/ghttp/ghttp_response_view.go | 18 +++++++++--------- net/ghttp/ghttp_response_writer.go | 2 +- os/gres/gres_instance.go | 2 +- os/gsession/gsession_storage_redis.go | 5 ++--- 7 files changed, 20 insertions(+), 22 deletions(-) diff --git a/container/garray/garray_normal_str.go b/container/garray/garray_normal_str.go index 71a6f2e36..0e178e156 100644 --- a/container/garray/garray_normal_str.go +++ b/container/garray/garray_normal_str.go @@ -407,9 +407,8 @@ func (a *StrArray) SubSlice(offset int, length ...int) []string { s := make([]string, size) copy(s, a.array[offset:]) return s - } else { - return a.array[offset:end] } + return a.array[offset:end] } // Append is alias of PushRight,please See PushRight. diff --git a/encoding/gurl/url.go b/encoding/gurl/url.go index 2e3d2d508..ca3631d9a 100644 --- a/encoding/gurl/url.go +++ b/encoding/gurl/url.go @@ -27,25 +27,25 @@ func Decode(str string) (string, error) { return url.QueryUnescape(str) } -// URL-encode according to RFC 3986. +// RawEncode .URL-encode according to RFC 3986. // See http://php.net/manual/en/function.rawurlencode.php. func RawEncode(str string) string { return strings.Replace(url.QueryEscape(str), "+", "%20", -1) } -// Decode URL-encoded strings. +// RawDecode Decode URL-encoded strings. // See http://php.net/manual/en/function.rawurldecode.php. func RawDecode(str string) (string, error) { return url.QueryUnescape(strings.Replace(str, "%20", "+", -1)) } -// Generate URL-encoded query string. +// BuildQuery Generate URL-encoded query string. // See http://php.net/manual/en/function.http-build-query.php. func BuildQuery(queryData url.Values) string { return queryData.Encode() } -// Parse a URL and return its components. +// ParseURL Parse a URL and return its components. // -1: all; 1: scheme; 2: host; 4: port; 8: user; 16: pass; 32: path; 64: query; 128: fragment. // See http://php.net/manual/en/function.parse-url.php. func ParseURL(str string, component int) (map[string]string, error) { diff --git a/errors/gerror/gerror.go b/errors/gerror/gerror.go index 23be7df27..85b80b465 100644 --- a/errors/gerror/gerror.go +++ b/errors/gerror/gerror.go @@ -6,8 +6,8 @@ // Package gerror provides simple functions to manipulate errors. // -// Very note that, this package is quite a basic package, which SHOULD NOT import extra -// packages except standard packages and internal packages, to avoid cycle imports. +// Very note that, this package is quite a basic package, which SHOULD NOT import extra packages +// except standard packages and internal packages, to avoid cycle imports. package gerror import ( diff --git a/net/ghttp/ghttp_response_view.go b/net/ghttp/ghttp_response_view.go index 4d0aa4ac2..bfc8c6287 100644 --- a/net/ghttp/ghttp_response_view.go +++ b/net/ghttp/ghttp_response_view.go @@ -18,42 +18,42 @@ import ( // WriteTpl parses and responses given template file. // The parameter `params` specifies the template variables for parsing. func (r *Response) WriteTpl(tpl string, params ...gview.Params) error { - if b, err := r.ParseTpl(tpl, params...); err != nil { + b, err := r.ParseTpl(tpl, params...) + if err != nil { if !gmode.IsProduct() { r.Write("Template Parsing Error: " + err.Error()) } return err - } else { - r.Write(b) } + r.Write(b) return nil } // WriteTplDefault parses and responses the default template file. // The parameter `params` specifies the template variables for parsing. func (r *Response) WriteTplDefault(params ...gview.Params) error { - if b, err := r.ParseTplDefault(params...); err != nil { + b, err := r.ParseTplDefault(params...) + if err != nil { if !gmode.IsProduct() { r.Write("Template Parsing Error: " + err.Error()) } return err - } else { - r.Write(b) } + r.Write(b) return nil } // WriteTplContent parses and responses the template content. // The parameter `params` specifies the template variables for parsing. func (r *Response) WriteTplContent(content string, params ...gview.Params) error { - if b, err := r.ParseTplContent(content, params...); err != nil { + b, err := r.ParseTplContent(content, params...) + if err != nil { if !gmode.IsProduct() { r.Write("Template Parsing Error: " + err.Error()) } return err - } else { - r.Write(b) } + r.Write(b) return nil } diff --git a/net/ghttp/ghttp_response_writer.go b/net/ghttp/ghttp_response_writer.go index 08ea3daee..5a8781a02 100644 --- a/net/ghttp/ghttp_response_writer.go +++ b/net/ghttp/ghttp_response_writer.go @@ -50,7 +50,7 @@ func (w *ResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) { return w.writer.(http.Hijacker).Hijack() } -// Flush OutputBuffer outputs the buffer to client and clears the buffer. +// Flush outputs the buffer to client and clears the buffer. func (w *ResponseWriter) Flush() { if w.hijacked { return diff --git a/os/gres/gres_instance.go b/os/gres/gres_instance.go index f9e3fff3f..e04dc4311 100644 --- a/os/gres/gres_instance.go +++ b/os/gres/gres_instance.go @@ -9,7 +9,7 @@ package gres import "github.com/gogf/gf/v2/container/gmap" const ( - // DefaultName Default group name for instance usage. + // DefaultName default group name for instance usage. DefaultName = "default" ) diff --git a/os/gsession/gsession_storage_redis.go b/os/gsession/gsession_storage_redis.go index 642b0d525..7f80f9f3d 100644 --- a/os/gsession/gsession_storage_redis.go +++ b/os/gsession/gsession_storage_redis.go @@ -77,7 +77,7 @@ func (s *StorageRedis) Get(ctx context.Context, id string, key string) (value in return nil, ErrorDisabled } -// GetMap retrieves all key-value pairs as map from storage. +// Data retrieves all key-value pairs as map from storage. func (s *StorageRedis) Data(ctx context.Context, id string) (data map[string]interface{}, err error) { return nil, ErrorDisabled } @@ -135,9 +135,8 @@ func (s *StorageRedis) GetSession(ctx context.Context, id string, ttl time.Durat } if data == nil { return gmap.NewStrAnyMapFrom(m, true), nil - } else { - data.Replace(m) } + data.Replace(m) return data, nil }