From 34ce2104cad324f444943c528746bf6d23643cd3 Mon Sep 17 00:00:00 2001 From: tyltr <31768692+tylitianrui@users.noreply.github.com> Date: Thu, 3 Jun 2021 20:12:51 +0800 Subject: [PATCH] optimize code and reduce code cyclomatic complexity (#2737) * optimize code and reduce code cyclomatic complexity * optimize if-condtion Co-authored-by: thinkerou --- binding/form.go | 6 ++---- debug.go | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/binding/form.go b/binding/form.go index b93c34cf42..040af9e209 100644 --- a/binding/form.go +++ b/binding/form.go @@ -22,10 +22,8 @@ func (formBinding) Bind(req *http.Request, obj interface{}) error { if err := req.ParseForm(); err != nil { return err } - if err := req.ParseMultipartForm(defaultMemory); err != nil { - if err != http.ErrNotMultipart { - return err - } + if err := req.ParseMultipartForm(defaultMemory); err != nil && err != http.ErrNotMultipart { + return err } if err := mapForm(obj, req.Form); err != nil { return err diff --git a/debug.go b/debug.go index 9bacc68571..ed313868e9 100644 --- a/debug.go +++ b/debug.go @@ -95,9 +95,7 @@ at initialization. ie. before any route is registered or the router is listening } func debugPrintError(err error) { - if err != nil { - if IsDebugging() { - fmt.Fprintf(DefaultErrorWriter, "[GIN-debug] [ERROR] %v\n", err) - } + if err != nil && IsDebugging() { + fmt.Fprintf(DefaultErrorWriter, "[GIN-debug] [ERROR] %v\n", err) } }