mirror of
https://github.com/kataras/iris.git
synced 2025-03-14 08:36:28 +01:00
minor - remove prego1.9 import paths for context.Context to not comfuse users
parent
9b9d3e24db
commit
0002a162cc
|
@ -29,7 +29,7 @@ type DirOptions struct {
|
||||||
ShowList bool
|
ShowList bool
|
||||||
// If `ShowList` is true then this function will be used instead
|
// If `ShowList` is true then this function will be used instead
|
||||||
// of the default one to show the list of files of a current requested directory(dir).
|
// of the default one to show the list of files of a current requested directory(dir).
|
||||||
DirList func(ctx context.Context, dirName string, dir http.File) error
|
DirList func(ctx iris.Context, dirName string, dir http.File) error
|
||||||
|
|
||||||
// When embedded.
|
// When embedded.
|
||||||
Asset func(name string) ([]byte, error)
|
Asset func(name string) ([]byte, error)
|
||||||
|
@ -37,7 +37,7 @@ type DirOptions struct {
|
||||||
AssetNames func() []string
|
AssetNames func() []string
|
||||||
|
|
||||||
// Optional validator that loops through each found requested resource.
|
// Optional validator that loops through each found requested resource.
|
||||||
AssetValidator func(ctx context.Context, name string) bool
|
AssetValidator func(ctx iris.Context, name string) bool
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
2
MVC.md
2
MVC.md
|
@ -140,7 +140,7 @@ Where `mvc.Result` is a `hero.Result` type alias, which is this interface one:
|
||||||
```go
|
```go
|
||||||
type Result interface {
|
type Result interface {
|
||||||
// Dispatch should sends the response to the context's response writer.
|
// Dispatch should sends the response to the context's response writer.
|
||||||
Dispatch(ctx context.Context)
|
Dispatch(ctx iris.Context)
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -180,7 +180,7 @@ type Context interface {
|
||||||
// Next calls all the next handler from the handlers chain,
|
// Next calls all the next handler from the handlers chain,
|
||||||
// it should be used inside a middleware.
|
// it should be used inside a middleware.
|
||||||
//
|
//
|
||||||
// Note: Custom context should override this method in order to be able to pass its own context.Context implementation.
|
// Note: Custom context should override this method in order to be able to pass its own iris.Context implementation.
|
||||||
Next()
|
Next()
|
||||||
// NextOr checks if chain has a next handler, if so then it executes it
|
// NextOr checks if chain has a next handler, if so then it executes it
|
||||||
// otherwise it sets a new chain assigned to this Context based on the given handler(s)
|
// otherwise it sets a new chain assigned to this Context based on the given handler(s)
|
||||||
|
@ -514,7 +514,7 @@ type Context interface {
|
||||||
// to be executed. Next handlers are being executed on iris because you can alt the
|
// to be executed. Next handlers are being executed on iris because you can alt the
|
||||||
// error code and change it to a more specific one, i.e
|
// error code and change it to a more specific one, i.e
|
||||||
// users := app.Party("/users")
|
// users := app.Party("/users")
|
||||||
// users.Done(func(ctx context.Context){ if ctx.StatusCode() == 400 { /* custom error code for /users */ }})
|
// users.Done(func(ctx iris.Context){ if ctx.StatusCode() == 400 { /* custom error code for /users */ }})
|
||||||
NotFound()
|
NotFound()
|
||||||
|
|
||||||
// +------------------------------------------------------------+
|
// +------------------------------------------------------------+
|
||||||
|
|
|
@ -33,7 +33,7 @@ func internalServerError(ctx iris.Context) {
|
||||||
ctx.WriteString("Oups something went wrong, try again")
|
ctx.WriteString("Oups something went wrong, try again")
|
||||||
}
|
}
|
||||||
|
|
||||||
func index(ctx context.Context) {
|
func index(ctx iris.Context) {
|
||||||
ctx.View("index.html")
|
ctx.View("index.html")
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
|
@ -25,14 +25,14 @@ import (
|
||||||
// 2.
|
// 2.
|
||||||
// Create your own custom Context, put any fields you'll need.
|
// Create your own custom Context, put any fields you'll need.
|
||||||
type MyContext struct {
|
type MyContext struct {
|
||||||
// Embed the `context.Context` -
|
// Embed the `iris.Context` -
|
||||||
// It's totally optional but you will need this if you
|
// It's totally optional but you will need this if you
|
||||||
// don't want to override all the context's methods!
|
// don't want to override all the context's methods!
|
||||||
context.Context
|
iris.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
// Optionally: validate MyContext implements context.Context on compile-time.
|
// Optionally: validate MyContext implements iris.Context on compile-time.
|
||||||
var _ context.Context = &MyContext{}
|
var _ iris.Context = &MyContext{}
|
||||||
|
|
||||||
// 3.
|
// 3.
|
||||||
func (ctx *MyContext) Do(handlers context.Handlers) {
|
func (ctx *MyContext) Do(handlers context.Handlers) {
|
||||||
|
@ -59,7 +59,7 @@ func main() {
|
||||||
app := iris.New()
|
app := iris.New()
|
||||||
|
|
||||||
// 4.
|
// 4.
|
||||||
app.ContextPool.Attach(func() context.Context {
|
app.ContextPool.Attach(func() iris.Context {
|
||||||
return &MyContext{
|
return &MyContext{
|
||||||
// If you use the embedded Context,
|
// If you use the embedded Context,
|
||||||
// call the `context.NewContext` to create one:
|
// call the `context.NewContext` to create one:
|
||||||
|
@ -72,7 +72,7 @@ func main() {
|
||||||
|
|
||||||
// Register your route, as you normally do
|
// Register your route, as you normally do
|
||||||
app.Handle("GET", "/", recordWhichContextForExample,
|
app.Handle("GET", "/", recordWhichContextForExample,
|
||||||
func(ctx context.Context) {
|
func(ctx iris.Context) {
|
||||||
// use the context's overridden HTML method.
|
// use the context's overridden HTML method.
|
||||||
ctx.HTML("<h1> Hello from my custom context's HTML! </h1>")
|
ctx.HTML("<h1> Hello from my custom context's HTML! </h1>")
|
||||||
})
|
})
|
||||||
|
@ -81,7 +81,7 @@ func main() {
|
||||||
// MyContext.Context embedded default context
|
// MyContext.Context embedded default context
|
||||||
// when MyContext is not directly define the View function by itself.
|
// when MyContext is not directly define the View function by itself.
|
||||||
app.Handle("GET", "/hi/{firstname:alphabetical}",recordWhichContextForExample,
|
app.Handle("GET", "/hi/{firstname:alphabetical}",recordWhichContextForExample,
|
||||||
func(ctx context.Context) {
|
func(ctx iris.Context) {
|
||||||
firstname := ctx.Values().GetString("firstname")
|
firstname := ctx.Values().GetString("firstname")
|
||||||
|
|
||||||
ctx.ViewData("firstname", firstname)
|
ctx.ViewData("firstname", firstname)
|
||||||
|
@ -94,7 +94,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Should always print "($PATH) Handler is executing from 'MyContext'"
|
// Should always print "($PATH) Handler is executing from 'MyContext'"
|
||||||
func recordWhichContextForExample(ctx context.Context) {
|
func recordWhichContextForExample(ctx iris.Context) {
|
||||||
ctx.Application().Logger().Infof("(%s) Handler is executing from: '%s'",
|
ctx.Application().Logger().Infof("(%s) Handler is executing from: '%s'",
|
||||||
ctx.Path(), reflect.TypeOf(ctx).Elem().Name())
|
ctx.Path(), reflect.TypeOf(ctx).Elem().Name())
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user