-
Notifications
You must be signed in to change notification settings - Fork 689
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implemented webservice and route level filter chains
see restful-filters.go for an example
- Loading branch information
Showing
7 changed files
with
123 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package restful | ||
|
||
// FilterChain is a request scoped object to process one or more filters before calling the target RouteFunction. | ||
type FilterChain struct { | ||
Filters []FilterFunction // ordered list of FilterFunction | ||
Index int // index into filters that is currently in progress | ||
Target RouteFunction // function to call after passing all filters | ||
} | ||
|
||
// ProcessFilter passes the request,response pair through the next of Filters. | ||
// Each filter can decide to proceed to the next Filter or handle the Response itself. | ||
func (f *FilterChain) ProcessFilter(request *Request, response *Response) { | ||
if f.Index < len(f.Filters) { | ||
f.Index++ | ||
f.Filters[f.Index-1](request, response, f) | ||
} else { | ||
f.Target(request, response) | ||
} | ||
} | ||
|
||
// FilterFunction definitions must call ProcessFilter on the FilterChain to pass on the control and eventually call the RouteFunction | ||
type FilterFunction func(*Request, *Response, *FilterChain) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters