1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-08 12:31:58 +00:00

8.4.0 | New MVC Features | Refactor examples and godoc for go 1.9 use. Read HISTORY.md.

Former-commit-id: 90c05e743052bc3722e7fefaa0cbb0ed5153a1fb
This commit is contained in:
kataras
2017-08-27 20:35:23 +03:00
parent a2de506f80
commit 42b123975c
100 changed files with 405 additions and 981 deletions

View File

@@ -4,7 +4,6 @@ import (
"time"
"github.com/kataras/iris"
"github.com/kataras/iris/context"
)
const (
@@ -19,7 +18,7 @@ func main() {
// set the view engine target to ./templates folder
app.RegisterView(iris.HTML("./templates", ".html").Reload(true))
app.Use(func(ctx context.Context) {
app.Use(func(ctx iris.Context) {
// set the title, current time and a layout in order to be used if and when the next handler(s) calls the .Render function
ctx.ViewData("Title", DefaultTitle)
now := time.Now().Format(ctx.Application().ConfigurationReadOnly().GetTimeFormat())
@@ -29,14 +28,14 @@ func main() {
ctx.Next()
})
app.Get("/", func(ctx context.Context) {
app.Get("/", func(ctx iris.Context) {
ctx.ViewData("BodyMessage", "a sample text here... setted by the route handler")
if err := ctx.View("index.html"); err != nil {
ctx.Application().Logger().Infof(err.Error())
}
})
app.Get("/about", func(ctx context.Context) {
app.Get("/about", func(ctx iris.Context) {
ctx.ViewData("Title", "My About Page")
ctx.ViewData("BodyMessage", "about text here... setted by the route handler")

View File

@@ -2,7 +2,6 @@ package main
import (
"github.com/kataras/iris"
"github.com/kataras/iris/context"
)
func main() {
@@ -23,7 +22,7 @@ type page struct {
Title, Name string
}
func hi(ctx context.Context) {
func hi(ctx iris.Context) {
ctx.ViewData("", page{Title: "Hi Page", Name: "iris"})
ctx.View("hi.html")
}

View File

@@ -2,7 +2,6 @@ package main
import (
"github.com/kataras/iris"
"github.com/kataras/iris/context"
)
func main() {
@@ -21,7 +20,7 @@ func main() {
// - {{ yield }}
// - {{ current }}
app.RegisterView(iris.HTML("./templates", ".html"))
app.Get("/", func(ctx context.Context) {
app.Get("/", func(ctx iris.Context) {
ctx.ViewData("Name", "iris") // the .Name inside the ./templates/hi.html
ctx.Gzip(true) // enable gzip for big files

View File

@@ -2,7 +2,6 @@ package main
import (
"github.com/kataras/iris"
"github.com/kataras/iris/context"
)
func main() {
@@ -34,7 +33,7 @@ func main() {
app.Run(iris.Addr(":8080"), iris.WithCharset("UTF-8")) // defaults to that but you can change it.
}
func hi(ctx context.Context) {
func hi(ctx iris.Context) {
ctx.ViewData("Title", "Hi Page")
ctx.ViewData("Name", "iris") // {{.Name}} will render: iris
// ctx.ViewData("", myCcustomStruct{})

View File

@@ -2,7 +2,6 @@ package main
import (
"github.com/kataras/iris"
"github.com/kataras/iris/context"
)
type mypage struct {
@@ -16,7 +15,7 @@ func main() {
app.RegisterView(iris.HTML("./templates", ".html").Layout("layout.html"))
// TIP: append .Reload(true) to reload the templates on each request.
app.Get("/", func(ctx context.Context) {
app.Get("/", func(ctx iris.Context) {
ctx.Gzip(true)
ctx.ViewData("", mypage{"My Page title", "Hello world!"})
ctx.View("mypage.html")

View File

@@ -2,7 +2,6 @@ package main
import (
"github.com/kataras/iris"
"github.com/kataras/iris/context"
)
func main() {
@@ -16,7 +15,7 @@ func main() {
app.RegisterView(tmpl)
app.Get("/", func(ctx context.Context) {
app.Get("/", func(ctx iris.Context) {
if err := ctx.View("page1.html"); err != nil {
ctx.StatusCode(iris.StatusInternalServerError)
ctx.Writef(err.Error())
@@ -24,7 +23,7 @@ func main() {
})
// remove the layout for a specific route
app.Get("/nolayout", func(ctx context.Context) {
app.Get("/nolayout", func(ctx iris.Context) {
ctx.ViewLayout(iris.NoLayout)
if err := ctx.View("page1.html"); err != nil {
ctx.StatusCode(iris.StatusInternalServerError)
@@ -35,10 +34,10 @@ func main() {
// set a layout for a party, .Layout should be BEFORE any Get or other Handle party's method
my := app.Party("/my").Layout("layouts/mylayout.html")
{ // both of these will use the layouts/mylayout.html as their layout.
my.Get("/", func(ctx context.Context) {
my.Get("/", func(ctx iris.Context) {
ctx.View("page1.html")
})
my.Get("/other", func(ctx context.Context) {
my.Get("/other", func(ctx iris.Context) {
ctx.View("page1.html")
})
}

View File

@@ -3,7 +3,6 @@ package main
import (
"github.com/kataras/iris"
"github.com/kataras/iris/context"
)
func main() {
@@ -30,7 +29,7 @@ func main() {
mypath6Route := app.Get("/mypath6/{paramfirst}/{paramsecond}/statichere/{paramThirdAfterStatic}", writePathHandler)
mypath6Route.Name = "my-page6"
app.Get("/", func(ctx context.Context) {
app.Get("/", func(ctx iris.Context) {
// for /mypath6...
paramsAsArray := []string{"theParam1", "theParam2", "paramThirdAfterStatic"}
ctx.ViewData("ParamsAsArray", paramsAsArray)
@@ -39,7 +38,7 @@ func main() {
}
})
app.Get("/redirect/{namedRoute}", func(ctx context.Context) {
app.Get("/redirect/{namedRoute}", func(ctx iris.Context) {
routeName := ctx.Params().Get("namedRoute")
r := app.GetRoute(routeName)
if r == nil {
@@ -63,6 +62,6 @@ func main() {
}
func writePathHandler(ctx context.Context) {
func writePathHandler(ctx iris.Context) {
ctx.Writef("Hello from %s.", ctx.Path())
}

View File

@@ -3,7 +3,6 @@ package main
import (
"github.com/kataras/iris"
"github.com/kataras/iris/context"
"github.com/kataras/iris/core/router"
)
@@ -48,7 +47,7 @@ func main() {
mypath6Route := subdomain.Get("/mypath6/{paramfirst}/{paramsecond}/staticParam/{paramThirdAfterStatic}", emptyHandler)
mypath6Route.Name = "my-page6"
app.Get("/", func(ctx context.Context) {
app.Get("/", func(ctx iris.Context) {
// for username5./mypath6...
paramsAsArray := []string{"username5", "theParam1", "theParam2", "paramThirdAfterStatic"}
ctx.ViewData("ParamsAsArray", paramsAsArray)
@@ -61,7 +60,7 @@ func main() {
app.Run(iris.Addr(host))
}
func emptyHandler(ctx context.Context) {
func emptyHandler(ctx iris.Context) {
ctx.Writef("Hello from subdomain: %s , you're in path: %s", ctx.Subdomain(), ctx.Path())
}