1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-18 02:17:05 +00:00
Former-commit-id: 75b855bee9216c28ce8e1ff46aee467766c37f23
This commit is contained in:
kataras
2017-08-13 01:47:19 +03:00
parent 960ddb9f72
commit 39a24fb7cb
8 changed files with 111 additions and 27 deletions

View File

@@ -20,8 +20,16 @@ type MyContext struct {
var _ context.Context = &MyContext{} // optionally: validate on compile-time if MyContext implements context.Context.
// Optional Part 2:
// The only one important if you will override the Context with an embedded context.Context inside it.
// The only one important if you will override the Context
// with an embedded context.Context inside it.
// Required in order to run the handlers via this "*MyContext".
func (ctx *MyContext) Do(handlers context.Handlers) {
context.Do(ctx, handlers)
}
// The second one important if you will override the Context
// with an embedded context.Context inside it.
// Required in order to run the chain of handlers via this "*MyContext".
func (ctx *MyContext) Next() {
context.Next(ctx)
}
@@ -40,11 +48,9 @@ func main() {
app := iris.New()
// app.Logger().SetLevel("debug")
// Register a view engine on .html files inside the ./view/** directory.
app.RegisterView(iris.HTML("./view", ".html"))
// The only one Required:
// here is how you define how your own context will be created and acquired from the iris' generic context pool.
// here is how you define how your own context will
// be created and acquired from the iris' generic context pool.
app.ContextPool.Attach(func() context.Context {
return &MyContext{
// Optional Part 3:
@@ -52,6 +58,9 @@ func main() {
}
})
// Register a view engine on .html files inside the ./view/** directory.
app.RegisterView(iris.HTML("./view", ".html"))
// register your route, as you normally do
app.Handle("GET", "/", recordWhichContextJustForProofOfConcept, func(ctx context.Context) {
// use the context's overridden HTML method.