-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from HotelsDotCom/master
added interceptor option
- Loading branch information
Showing
5 changed files
with
241 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package vestigo | ||
|
||
import "net/http" | ||
|
||
type Interceptor interface { | ||
// returns true if the interceptor should run before handler | ||
Before() bool | ||
// returns true if the interceptor should run after handler | ||
After() bool | ||
// the actual intercept function, returns true if the request should continue to handler and/or | ||
// chained interceptors, false if the execution should terminate | ||
Intercept(w http.ResponseWriter, r *http.Request) bool | ||
} |
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,27 @@ | ||
package vestigo | ||
|
||
import "net/http" | ||
|
||
type MockInterceptor struct { | ||
before bool | ||
intercept bool | ||
after bool | ||
CalledIntercept int | ||
} | ||
|
||
func (m *MockInterceptor) Before() bool { | ||
return m.before | ||
} | ||
|
||
func (m *MockInterceptor) After() bool { | ||
return m.after | ||
} | ||
|
||
func (m *MockInterceptor) Intercept(w http.ResponseWriter, r *http.Request) bool { | ||
m.CalledIntercept += 1 | ||
return m.intercept | ||
} | ||
|
||
func NewMockInterceptor(before, intercept, after bool) *MockInterceptor { | ||
return &MockInterceptor{before: before, intercept: intercept, after: after} | ||
} |
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