mirror of
https://github.com/kataras/iris.git
synced 2025-03-21 18:46:29 +01:00
Align doc.go
Former-commit-id: 6d78bc5aec83ddeb15e068679ec1da33fd16e32e
This commit is contained in:
parent
1851d49b58
commit
5a1e9cd13f
54
doc.go
54
doc.go
|
@ -58,7 +58,7 @@ Example code:
|
|||
"gopkg.in/kataras/iris.v6/adaptors/httprouter" // <--- or adaptors/gorillamux
|
||||
)
|
||||
|
||||
func main(){
|
||||
func main() {
|
||||
app := iris.New()
|
||||
app.Adapt(httprouter.New()) // <--- or gorillamux.New()
|
||||
|
||||
|
@ -67,15 +67,15 @@ Example code:
|
|||
// Handler(s): index
|
||||
app.Get("/", index)
|
||||
|
||||
|
||||
app.Listen(":80")
|
||||
}
|
||||
|
||||
func index(ctx *iris.Context){
|
||||
func index(ctx *iris.Context) {
|
||||
ctx.HTML(iris.StatusOK, "<h1> Welcome to my page!</h1>")
|
||||
}
|
||||
|
||||
|
||||
|
||||
All HTTP methods are supported, users can register handlers for same paths on different methods.
|
||||
The first parameter is the HTTP Method,
|
||||
second parameter is the request path of the route,
|
||||
|
@ -379,27 +379,31 @@ Example code:
|
|||
package main
|
||||
|
||||
import (
|
||||
"gopkg.in/kataras/iris.v6"
|
||||
"github.com/kataras/adaptors/gorillamux"
|
||||
"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.
|
||||
myCors := func(opts cors.Options) iris.HandlerFunc {
|
||||
handlerWithNext := cors.New(opts).ServeHTTP
|
||||
func newCorsMiddleware() iris.HandlerFunc {
|
||||
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.
|
||||
return iris.ToHandler(handlerWithNext)
|
||||
}
|
||||
|
||||
func main(){
|
||||
func main() {
|
||||
app := iris.New()
|
||||
app.Adapt(httprouter.New())
|
||||
app.Adapt(gorillamux.New())
|
||||
|
||||
// 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) {
|
||||
// ....
|
||||
})
|
||||
|
||||
|
@ -416,23 +420,23 @@ as `context.ResponseWriter` is an `io.Writer`.
|
|||
All of these five template engines have common features with common API,
|
||||
like Layout, Template Funcs, Party-specific layout, partial rendering and more.
|
||||
|
||||
- the standard html, based on https://github.com/kataras/go-template/tree/master/html
|
||||
its template parser is the https://golang.org/pkg/html/template/.
|
||||
- the standard html, based on https://github.com/kataras/go-template/tree/master/html
|
||||
its template parser is the https://golang.org/pkg/html/template/.
|
||||
|
||||
- django, based on https://github.com/kataras/go-template/tree/master/django
|
||||
its template parser is the https://github.com/flosch/pongo2
|
||||
- django, based on https://github.com/kataras/go-template/tree/master/django
|
||||
its template parser is the https://github.com/flosch/pongo2
|
||||
|
||||
- pug, based on https://github.com/kataras/go-template/tree/master/pug
|
||||
its template parser is the https://github.com/Joker/jade
|
||||
- pug, based on https://github.com/kataras/go-template/tree/master/pug
|
||||
its template parser is the https://github.com/Joker/jade
|
||||
|
||||
- handlebars, based on https://github.com/kataras/go-template/tree/master/handlebars
|
||||
its template parser is the https://github.com/aymerick/raymond
|
||||
- handlebars, based on https://github.com/kataras/go-template/tree/master/handlebars
|
||||
its template parser is the https://github.com/aymerick/raymond
|
||||
|
||||
- amber, based on https://github.com/kataras/go-template/tree/master/amber
|
||||
its template parser is the https://github.com/eknkc/amber
|
||||
- amber, based on https://github.com/kataras/go-template/tree/master/amber
|
||||
its template parser is the https://github.com/eknkc/amber
|
||||
|
||||
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:
|
||||
|
||||
|
@ -468,7 +472,7 @@ Example code:
|
|||
//
|
||||
// to adapt custom funcs, use:
|
||||
app.Adapt(iris.TemplateFuncsPolicy{"myfunc": func(s string) string {
|
||||
return "hi "+s
|
||||
return "hi " + s
|
||||
}}) // usage inside template: {{ hi "kataras"}}
|
||||
|
||||
app.Get("/hi", func(ctx *iris.Context) {
|
||||
|
@ -487,6 +491,7 @@ Example code:
|
|||
app.Listen(":8080")
|
||||
}
|
||||
|
||||
|
||||
View engine supports bundled(https://github.com/jteeuwen/go-bindata) template files too.
|
||||
go-bindata gives you two functions, asset and assetNames,
|
||||
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:
|
||||
|
||||
- examples: https://github.com/iris-contrib/examples
|
||||
- book: https://docs.iris-go.com
|
||||
- adaptors: https://github.com/kataras/iris/tree/v6/adaptors
|
||||
- middleware: https://github.com/kataras/iris/tree/v6/middleware & https://github.com/iris-contrib/middleware
|
||||
- godocs: https://godoc.org/github.com/kataras/iris
|
||||
|
|
Loading…
Reference in New Issue
Block a user