mirror of
https://github.com/kataras/iris.git
synced 2025-02-02 15:30:36 +01:00
Align doc.go
Former-commit-id: 6d78bc5aec83ddeb15e068679ec1da33fd16e32e
This commit is contained in:
parent
1851d49b58
commit
5a1e9cd13f
26
doc.go
26
doc.go
|
@ -67,7 +67,6 @@ Example code:
|
||||||
// Handler(s): index
|
// Handler(s): index
|
||||||
app.Get("/", index)
|
app.Get("/", index)
|
||||||
|
|
||||||
|
|
||||||
app.Listen(":80")
|
app.Listen(":80")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,6 +75,7 @@ Example code:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
All HTTP methods are supported, users can register handlers for same paths on different methods.
|
All HTTP methods are supported, users can register handlers for same paths on different methods.
|
||||||
The first parameter is the HTTP Method,
|
The first parameter is the HTTP Method,
|
||||||
second parameter is the request path of the route,
|
second parameter is the request path of the route,
|
||||||
|
@ -379,27 +379,31 @@ Example code:
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"gopkg.in/kataras/iris.v6"
|
|
||||||
"github.com/kataras/adaptors/gorillamux"
|
|
||||||
"github.com/rs/cors"
|
"github.com/rs/cors"
|
||||||
|
"gopkg.in/kataras/iris.v6"
|
||||||
|
"gopkg.in/kataras/iris.v6/adaptors/gorillamux"
|
||||||
)
|
)
|
||||||
|
|
||||||
// myCors returns a new cors middleware
|
// newCorsMiddleware returns a new cors middleware
|
||||||
// with the provided options.
|
// with the provided options.
|
||||||
myCors := func(opts cors.Options) iris.HandlerFunc {
|
func newCorsMiddleware() iris.HandlerFunc {
|
||||||
handlerWithNext := cors.New(opts).ServeHTTP
|
options := cors.Options{
|
||||||
|
AllowedOrigins: []string{"*"},
|
||||||
|
}
|
||||||
|
handlerWithNext := cors.New(options).ServeHTTP
|
||||||
|
|
||||||
// this is the only func you will have to use if you're going to make use of any external net/http middleware.
|
// this is the only func you will have to use if you're going
|
||||||
|
// to make use of any external net/http middleware.
|
||||||
// iris.ToHandler converts the net/http middleware to an iris-compatible.
|
// iris.ToHandler converts the net/http middleware to an iris-compatible.
|
||||||
return iris.ToHandler(handlerWithNext)
|
return iris.ToHandler(handlerWithNext)
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
app := iris.New()
|
app := iris.New()
|
||||||
app.Adapt(httprouter.New())
|
app.Adapt(gorillamux.New())
|
||||||
|
|
||||||
// Any registers a route to all http methods.
|
// Any registers a route to all http methods.
|
||||||
app.Any("/user", myCors(cors.Options{AllowOrigins: "*"}), func(ctx *iris.Context){
|
app.Any("/user", newCorsMiddleware(), func(ctx *iris.Context) {
|
||||||
// ....
|
// ....
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -432,7 +436,7 @@ like Layout, Template Funcs, Party-specific layout, partial rendering and more.
|
||||||
its template parser is the https://github.com/eknkc/amber
|
its template parser is the https://github.com/eknkc/amber
|
||||||
|
|
||||||
Each one of these template engines has different options,
|
Each one of these template engines has different options,
|
||||||
view adaptors are located here: https://github.com/kataras/iris/tree/master/adaptors/view .
|
view adaptors are located here: https://github.com/kataras/iris/tree/v6/adaptors/view .
|
||||||
|
|
||||||
Example code:
|
Example code:
|
||||||
|
|
||||||
|
@ -487,6 +491,7 @@ Example code:
|
||||||
app.Listen(":8080")
|
app.Listen(":8080")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
View engine supports bundled(https://github.com/jteeuwen/go-bindata) template files too.
|
View engine supports bundled(https://github.com/jteeuwen/go-bindata) template files too.
|
||||||
go-bindata gives you two functions, asset and assetNames,
|
go-bindata gives you two functions, asset and assetNames,
|
||||||
these can be setted to each of the template engines using the `.Binary` func.
|
these can be setted to each of the template engines using the `.Binary` func.
|
||||||
|
@ -514,7 +519,6 @@ You should have a basic idea of the framework by now, we just scratched the surf
|
||||||
If you enjoy what you just saw and want to learn more, please follow the below links:
|
If you enjoy what you just saw and want to learn more, please follow the below links:
|
||||||
|
|
||||||
- examples: https://github.com/iris-contrib/examples
|
- examples: https://github.com/iris-contrib/examples
|
||||||
- book: https://docs.iris-go.com
|
|
||||||
- adaptors: https://github.com/kataras/iris/tree/v6/adaptors
|
- adaptors: https://github.com/kataras/iris/tree/v6/adaptors
|
||||||
- middleware: https://github.com/kataras/iris/tree/v6/middleware & https://github.com/iris-contrib/middleware
|
- middleware: https://github.com/kataras/iris/tree/v6/middleware & https://github.com/iris-contrib/middleware
|
||||||
- godocs: https://godoc.org/github.com/kataras/iris
|
- godocs: https://godoc.org/github.com/kataras/iris
|
||||||
|
|
Loading…
Reference in New Issue
Block a user