Comments (2)
I did some legwork and ran a test:
func check0() {
return;
}
func check1(res http.ResponseWriter) string{
return "1"
}
func check2(c martini.Context, res http.ResponseWriter) string{
if true {
return "hiii";
}
c.Next()
return "2"
}
func check3(c martini.Context, res http.ResponseWriter) string{
c.Next()
return "3"
}
func check4(res http.ResponseWriter) {
res.Write([]byte("4"))
}
func check5(c martini.Context, res http.ResponseWriter) string{
res.Write([]byte("5.0"))
c.Next()
return "5.1"
}
func finish(res http.ResponseWriter){
fmt.Println("in finish")
res.Write([]byte("all done"))
}
func Routes(m *martini.ClassicMartini) {
m.Get("/cp/meta/middleware0", check0, finish)
m.Get("/cp/meta/middleware1", check1, finish)
m.Get("/cp/meta/middleware2", check2, finish)
m.Get("/cp/meta/middleware3", check3, finish)
m.Get("/cp/meta/middleware4", check4, finish)
m.Get("/cp/meta/middleware5", check5, finish)
}
the results I got:
GET /cp/meta/middleware0 => all done
GET /cp/meta/middleware1 => 1
GET /cp/meta/middleware2 => hiii
GET /cp/meta/middleware3 => all done3
GET /cp/meta/middleware4 => 4
GET /cp/meta/middleware5 => 5.0all done5.1
what surprised me is that the subsequent middleware (the finish() func) was not called for :
GET /cp/meta/middleware4
what is the reason for this? Other than that, the rule seems to be if the middleware func returns anything (return args length > 0), then no more middleware is called unless c.Next() is called of course).
Please document which scenarios cause middleware to stop being called and/or how to continue calling subsequent registered middleware.
from martini.
I add the Break()
method for martini's context like this:
func (c *context) Break() {
// skip other handlers plus one possible action
c.index = len(c.handlers) + 1
c.run()
}
This will skip the loop in func (c *context) run()
.
from martini.
Related Issues (20)
- Does martini really support html5 Mode serving of static files? HOT 1
- Why HEAD method called on Get Routing?
- Link broken HOT 1
- Handling Gorilla Websockets
- Website hacked? HOT 1
- Wrong link? http://martini.codegangsta.io shows online gambling advertisement only HOT 1
- Use render.Render in ReturnHandler
- unit
- Unit Test
- Add support for promhttp HOT 2
- Hook to log errors if status code > 399 HOT 1
- typecheck arguments on boot-up
- How to include auth middleware that handles roles for logged-in users HOT 1
- cannot set headers HOT 1
- Problems with # in route matching HOT 1
- Contribution, Arabic translation
- How to become a maintainer?
- is this project dead? HOT 2
- Football
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from martini.