You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-`pattern`: string or regex to match against router rules. Use `/*` to match all.
58
+
58
59
-`pos`: the place to execute the Filter. There are five fixed parameters representing different execution processes.
59
60
- web.BeforeStatic: Before finding the static file.
60
61
- web.BeforeRouter: Before finding router.
61
62
- web.BeforeExec: After finding router and before executing the matched Controller.
62
63
- web.AfterExec: After executing Controller.
63
64
- web.FinishRouter: After finishing router.
65
+
64
66
-`filter`: filter function type FilterFunc func(*context.Context)
67
+
65
68
-`opts`:
66
-
-`web.WithReturnOnOutput`: sets the value of `returnOnOutput` (default `true`), if there is already output before this filter is performed, whether to not continue to execute this filter, the default setting is that if there is already output before (parameter `true`), then this filter will not be executed.
69
+
70
+
-`web.WithReturnOnOutput`: sets the value of `returnOnOutput` (default `true`), if there is already output before this filter is performed, whether to not continue to execute this filter, the default setting is that if there is already output before (parameter `true`), then this filter will not be executed.
71
+
72
+
(**Note: When using the AfterExec or FinishRouter positions, you must set WithReturnOnOutput to false, otherwise the filter will not take effect. See the example below for details.**);
73
+
67
74
-`web.WithResetParams`: Whether to reset the `filter` parameter, the default is `false`, because in case of conflict between the `pattern` of the `filter` and the `pattern` of the route itself, you can reset the `filter` parameter, so as to ensure that the correct parameter is obtained in the subsequent logic, for example, if the filter of `/api/*` is set, and the router of `/api/docs/*` is set at the same time, then when the router of `/api/docs/*` is executed, then the correct parameter is obtained in the subsequent logic. For example, if you set the filter of `/api/*` and also set the router of `/api/docs/*`, then when you access `/api/docs/swagger/abc.js`, set `:splat` parameter to `docs/swagger/abc.js` when executing `filter`, but if the option is `false`, it will keep `docs/swagger/abc.js` when executing the routing logic, and reset the `:splat` parameter if `true` is set.
75
+
68
76
-`web.WithCaseSensitive`: case sensitive;
69
77
70
78
If it is not clear how to use these options, the best way is to write a few tests yourself to experiment with their effects.
71
79
80
+
For example, here is an example of the InsertFilter method in the current beego project:
81
+
82
+
```go
83
+
// ExampleInsertFilter is an example of how to use InsertFilter
0 commit comments