Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻️ Refactor: Use func in app.go #2597

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading