Use registers a middleware route that will match requests with the provided prefix (which is optional and defaults to "/"). Also, you can pass another app instance as a sub-router along a routing path. It's very useful to split up a large API as many independent routers and compose them as a single
(args ...any)
| 68 | // |
| 69 | // This method will match all HTTP verbs: GET, POST, PUT, HEAD etc... |
| 70 | func (grp *Group) Use(args ...any) Router { |
| 71 | var subApp *App |
| 72 | var prefix string |
| 73 | var prefixes []string |
| 74 | var handlers []Handler |
| 75 | |
| 76 | for i := range args { |
| 77 | switch arg := args[i].(type) { |
| 78 | case string: |
| 79 | prefix = arg |
| 80 | case *App: |
| 81 | subApp = arg |
| 82 | case []string: |
| 83 | prefixes = arg |
| 84 | default: |
| 85 | handler, ok := toFiberHandler(arg) |
| 86 | if !ok { |
| 87 | panic(fmt.Sprintf("use: invalid handler %v\n", reflect.TypeOf(arg))) |
| 88 | } |
| 89 | handlers = append(handlers, handler) |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | if len(prefixes) == 0 { |
| 94 | prefixes = append(prefixes, prefix) |
| 95 | } |
| 96 | |
| 97 | for _, prefix := range prefixes { |
| 98 | if subApp != nil { |
| 99 | return grp.mount(prefix, subApp) |
| 100 | } |
| 101 | |
| 102 | grp.app.register([]string{methodUse}, getGroupPath(grp.Prefix, prefix), grp, handlers...) |
| 103 | } |
| 104 | |
| 105 | if !grp.hasAnyRoute { |
| 106 | grp.hasAnyRoute = true |
| 107 | } |
| 108 | |
| 109 | return grp |
| 110 | } |
| 111 | |
| 112 | // Get registers a route for GET methods that requests a representation |
| 113 | // of the specified resource. Requests using GET should only retrieve data. |
nothing calls this directly
no test coverage detected