mirror of
https://github.com/kataras/iris.git
synced 2025-12-24 05:17:03 +00:00
replace ioutil with io package and other minor improvements
This commit is contained in:
@@ -7,14 +7,15 @@ import (
|
||||
"github.com/kataras/iris/v12/core/router"
|
||||
)
|
||||
|
||||
/* A Router should contain all three of the following methods:
|
||||
- HandleRequest should handle the request based on the Context.
|
||||
HandleRequest(ctx iris.Context)
|
||||
- Build should builds the handler, it's being called on router's BuildRouter.
|
||||
Build(provider router.RoutesProvider) error
|
||||
- RouteExists reports whether a particular route exists.
|
||||
RouteExists(ctx iris.Context, method, path string) bool
|
||||
- FireErrorCode(ctx iris.Context) should handle the given ctx.GetStatusCode().
|
||||
/*
|
||||
A Router should contain all three of the following methods:
|
||||
- HandleRequest should handle the request based on the Context.
|
||||
HandleRequest(ctx iris.Context)
|
||||
- Build should builds the handler, it's being called on router's BuildRouter.
|
||||
Build(provider router.RoutesProvider) error
|
||||
- RouteExists reports whether a particular route exists.
|
||||
RouteExists(ctx iris.Context, method, path string) bool
|
||||
- FireErrorCode(ctx iris.Context) should handle the given ctx.GetStatusCode().
|
||||
|
||||
For a more detailed, complete and useful example
|
||||
you can take a look at the iris' router itself which is located at:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -29,7 +29,7 @@ func (r resource) loadFromBase(dir string) string {
|
||||
|
||||
fullpath := filepath.Join(dir, filename)
|
||||
|
||||
b, err := ioutil.ReadFile(fullpath)
|
||||
b, err := os.ReadFile(fullpath)
|
||||
if err != nil {
|
||||
panic(fullpath + " failed with error: " + err.Error())
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
/*Package main is a simple example of the behavior change of the execution flow of the handlers,
|
||||
/*
|
||||
Package main is a simple example of the behavior change of the execution flow of the handlers,
|
||||
normally we need the `ctx.Next()` to call the next handler in a route's handler chain,
|
||||
but with the `ExecutionRules` we can change this default behavior.
|
||||
Please read below before continue.
|
||||
@@ -8,11 +9,11 @@ The `Party#SetExecutionRules` alters the execution flow of the route handlers.
|
||||
For example, if for some reason the desired result is the (done or all) handlers
|
||||
to be executed no matter what, even if no `ctx.Next()` is called in the previous handlers:
|
||||
|
||||
app.SetExecutionRules(iris.ExecutionRules {
|
||||
Begin: iris.ExecutionOptions{Force: true}, # begin handlers(.Use)
|
||||
Main: iris.ExecutionOptions{Force: true}, # main handler (.Handle/Get...)
|
||||
Done: iris.ExecutionOptions{Force: true}, # done handlers (.Done)
|
||||
})
|
||||
app.SetExecutionRules(iris.ExecutionRules {
|
||||
Begin: iris.ExecutionOptions{Force: true}, # begin handlers(.Use)
|
||||
Main: iris.ExecutionOptions{Force: true}, # main handler (.Handle/Get...)
|
||||
Done: iris.ExecutionOptions{Force: true}, # done handlers (.Done)
|
||||
})
|
||||
|
||||
Note that if `true` then the only remained way to "break" the handler chain
|
||||
is by calling the `ctx.StopExecution()` (now that `ctx.Next()` doesn't even matter).
|
||||
@@ -22,7 +23,6 @@ the same rules will be applied to that as well.
|
||||
|
||||
Reset of these rules to their defaults (before `Party#Handle`) can be done
|
||||
with `Party#SetExecutionRules(iris.ExecutionRules{})`.
|
||||
|
||||
*/
|
||||
package main
|
||||
|
||||
|
||||
Reference in New Issue
Block a user