Skip to content

Commit

Permalink
♻️ Refactor: Use func in app.go
Browse files Browse the repository at this point in the history
Remove if statement
Reduce Scope of Variable
  • Loading branch information
LimJiAn committed Aug 24, 2023
1 parent 8ec7cec commit 252a9a6
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -683,27 +683,22 @@ func (app *App) GetRoutes(filterUseOption ...bool) []Route {
//
// This method will match all HTTP verbs: GET, POST, PUT, HEAD etc...
func (app *App) Use(args ...interface{}) Router {
var prefix string
var prefixes []string
var handlers []Handler

for i := 0; i < len(args); i++ {
switch arg := args[i].(type) {
for _, arg := range args {
switch arg := arg.(type) {
case string:
prefix = arg
prefixes = append(prefixes, arg)
case []string:
prefixes = arg
prefixes = append(prefixes, arg...)
case Handler:
handlers = append(handlers, arg)
default:
panic(fmt.Sprintf("use: invalid handler %v\n", reflect.TypeOf(arg)))
}
}

if len(prefixes) == 0 {
prefixes = append(prefixes, prefix)
}

for _, prefix := range prefixes {
app.register(methodUse, prefix, nil, handlers...)
}
Expand Down

0 comments on commit 252a9a6

Please sign in to comment.