From 4d3dfc868249568867845ae23a551213f81a3035 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Mon, 13 May 2024 13:40:04 +0800 Subject: [PATCH] refactor: refactor context handling and nil checks - Refactor nil checks to improve readability in `context.go` - Modify the control flow in `HandlerNames` and `Next` methods to continue on nil values before appending or invoking handlers in `context.go` Signed-off-by: Bo-Yi Wu --- context.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/context.go b/context.go index 96cab1f7..cd2645a9 100644 --- a/context.go +++ b/context.go @@ -152,9 +152,10 @@ func (c *Context) HandlerName() string { func (c *Context) HandlerNames() []string { hn := make([]string, 0, len(c.handlers)) for _, val := range c.handlers { - if nil != val { - hn = append(hn, nameOfFunction(val)) + if val == nil { + continue } + hn = append(hn, nameOfFunction(val)) } return hn } @@ -184,9 +185,10 @@ func (c *Context) FullPath() string { func (c *Context) Next() { c.index++ for c.index < int8(len(c.handlers)) { - if nil != c.handlers[c.index] { - c.handlers[c.index](c) + if c.handlers[c.index] == nil { + continue } + c.handlers[c.index](c) c.index++ } }