mirror of
https://github.com/kataras/iris.git
synced 2025-02-02 15:30:36 +01:00
add h2 header manually for pre-go 1.9 users when manually key files are being used
Former-commit-id: edf521fc02de87b53cd3bdf0b8e77610dd535862
This commit is contained in:
parent
bd779117fe
commit
fcfc65a7bc
|
@ -90,6 +90,9 @@ Navigate through examples for a better understanding.
|
|||
* [method overriding](routing/custom-context/method-overriding/main.go)
|
||||
* [new implementation](routing/custom-context/new-implementation/main.go)
|
||||
- [Route State](routing/route-state/main.go)
|
||||
- [Writing a middleware](routing/writing-a-middleware)
|
||||
* [per-route](routing/writing-a-middleware/per-route/main.go)
|
||||
* [globally](routing/writing-a-middleware/globally/main.go)
|
||||
|
||||
### MVC
|
||||
|
||||
|
|
56
_examples/routing/writing-a-middleware/globally/main.go
Normal file
56
_examples/routing/writing-a-middleware/globally/main.go
Normal file
|
@ -0,0 +1,56 @@
|
|||
package main
|
||||
|
||||
import "github.com/kataras/iris"
|
||||
|
||||
func main() {
|
||||
app := iris.New()
|
||||
// register the "before" handler as the first handler which will be executed
|
||||
// on all domain's routes.
|
||||
// or use the `UseGlobal` to register a middleware which will fire across subdomains.
|
||||
app.Use(before)
|
||||
// register the "after" handler as the last handler which will be executed
|
||||
// after all domain's routes' handler(s).
|
||||
app.Done(after)
|
||||
|
||||
// register our routes.
|
||||
app.Get("/", indexHandler)
|
||||
app.Get("/contact", contactHandler)
|
||||
|
||||
app.Run(iris.Addr(":8080"))
|
||||
}
|
||||
|
||||
func before(ctx iris.Context) {
|
||||
shareInformation := "this is a sharable information between handlers"
|
||||
|
||||
requestPath := ctx.Path()
|
||||
println("Before the indexHandler or contactHandler: " + requestPath)
|
||||
|
||||
ctx.Values().Set("info", shareInformation)
|
||||
ctx.Next()
|
||||
}
|
||||
|
||||
func after(ctx iris.Context) {
|
||||
println("After the indexHandler or contactHandler")
|
||||
}
|
||||
|
||||
func indexHandler(ctx iris.Context) {
|
||||
println("Inside indexHandler")
|
||||
|
||||
// take the info from the "before" handler.
|
||||
info := ctx.Values().GetString("info")
|
||||
|
||||
// write something to the client as a response.
|
||||
ctx.HTML("<h1>Response</h1>")
|
||||
ctx.HTML("<br/> Info: " + info)
|
||||
|
||||
ctx.Next() // execute the "after" handler registered via `Done`.
|
||||
}
|
||||
|
||||
func contactHandler(ctx iris.Context) {
|
||||
println("Inside contactHandler")
|
||||
|
||||
// write something to the client as a response.
|
||||
ctx.HTML("<h1>Contact</h1>")
|
||||
|
||||
ctx.Next() // execute the "after" handler registered via `Done`.
|
||||
}
|
36
_examples/routing/writing-a-middleware/per-route/main.go
Normal file
36
_examples/routing/writing-a-middleware/per-route/main.go
Normal file
|
@ -0,0 +1,36 @@
|
|||
package main
|
||||
|
||||
import "github.com/kataras/iris"
|
||||
|
||||
func main() {
|
||||
app := iris.New()
|
||||
app.Get("/", before, mainHandler, after)
|
||||
app.Run(iris.Addr(":8080"))
|
||||
}
|
||||
|
||||
func before(ctx iris.Context) {
|
||||
shareInformation := "this is a sharable information between handlers"
|
||||
|
||||
requestPath := ctx.Path()
|
||||
println("Before the mainHandler: " + requestPath)
|
||||
|
||||
ctx.Values().Set("info", shareInformation)
|
||||
ctx.Next() // execute the next handler, in this case the main one.
|
||||
}
|
||||
|
||||
func after(ctx iris.Context) {
|
||||
println("After the mainHandler")
|
||||
}
|
||||
|
||||
func mainHandler(ctx iris.Context) {
|
||||
println("Inside mainHandler")
|
||||
|
||||
// take the info from the "before" handler.
|
||||
info := ctx.Values().GetString("info")
|
||||
|
||||
// write something to the client as a response.
|
||||
ctx.HTML("<h1>Response</h1>")
|
||||
ctx.HTML("<br/> Info: " + info)
|
||||
|
||||
ctx.Next() // execute the "after".
|
||||
}
|
|
@ -251,6 +251,8 @@ func (su *Supervisor) ListenAndServeTLS(certFile string, keyFile string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// manually inserted as pre-go 1.9 for any case.
|
||||
cfg.NextProtos = []string{"h2", "http/1.1"}
|
||||
su.Server.TLSConfig = cfg
|
||||
return su.ListenAndServe()
|
||||
}
|
||||
|
|
10
doc.go
10
doc.go
|
@ -1222,14 +1222,14 @@ Example code:
|
|||
View Engine
|
||||
|
||||
|
||||
iris supports 5 template engines out-of-the-box, developers can still use any external golang template engine,
|
||||
Iris supports 5 template engines out-of-the-box, developers can still use any external golang template engine,
|
||||
as `context/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,
|
||||
its template parser is the golang.org/pkg/html/template/.
|
||||
its template parser is the golang.org/pkg/html/template/
|
||||
|
||||
Django,
|
||||
its template parser is the github.com/flosch/pongo2
|
||||
|
@ -1251,7 +1251,7 @@ Example code:
|
|||
import "github.com/kataras/iris"
|
||||
|
||||
func main() {
|
||||
app := iris.New() // defaults to these
|
||||
app := iris.New()
|
||||
|
||||
// - standard html | iris.HTML(...)
|
||||
// - django | iris.Django(...)
|
||||
|
@ -1268,9 +1268,13 @@ Example code:
|
|||
// - {{ render_r "header.html" }} // partial relative path to current page
|
||||
// - {{ yield }}
|
||||
// - {{ current }}
|
||||
|
||||
// register a custom template func.
|
||||
tmpl.AddFunc("greet", func(s string) string {
|
||||
return "Greetings " + s + "!"
|
||||
})
|
||||
|
||||
// register the view engine to the views, this will load the templates.
|
||||
app.RegisterView(tmpl)
|
||||
|
||||
app.Get("/", hi)
|
||||
|
|
Loading…
Reference in New Issue
Block a user