Skip to content

Commit

Permalink
refactor: refactor context handling and nil checks
Browse files Browse the repository at this point in the history
- 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 <[email protected]>
  • Loading branch information
appleboy committed May 13, 2024
1 parent 83036d4 commit 4d3dfc8
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check warning on line 156 in context.go

View check run for this annotation

Codecov / codecov/patch

context.go#L156

Added line #L156 was not covered by tests
}
hn = append(hn, nameOfFunction(val))
}
return hn
}
Expand Down Expand Up @@ -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

Check warning on line 189 in context.go

View check run for this annotation

Codecov / codecov/patch

context.go#L189

Added line #L189 was not covered by tests
}
c.handlers[c.index](c)
c.index++
}
}
Expand Down

0 comments on commit 4d3dfc8

Please sign in to comment.