1
0
mirror of https://github.com/kataras/iris.git synced 2026-05-10 16:13:46 +00:00

update code for go version 1.24

This commit is contained in:
Gerasimos (Makis) Maropoulos
2025-03-30 00:41:54 +02:00
parent e5e5d6f68f
commit 630c67ea6d
90 changed files with 337 additions and 167 deletions

View File

@@ -1,6 +1,10 @@
package main
import "github.com/kataras/iris/v12"
import (
"fmt"
"github.com/kataras/iris/v12"
)
func main() {
app := iris.New()
@@ -38,7 +42,7 @@ func index(ctx iris.Context) {
ctx.ViewLayout("main")
if err := ctx.View("index", data); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
}
@@ -50,7 +54,7 @@ func admin(ctx iris.Context) {
ctx.ViewLayout("main")
if err := ctx.View("index", data); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
}
@@ -68,7 +72,7 @@ func onFly(ctx iris.Context) {
}
if err := ctx.View("index", data); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
}

View File

@@ -1,6 +1,10 @@
package main
import "github.com/kataras/iris/v12"
import (
"fmt"
"github.com/kataras/iris/v12"
)
func main() {
app := iris.New()
@@ -20,7 +24,7 @@ func main() {
app.Get("/", func(ctx iris.Context) {
if err := ctx.View("page1.html"); err != nil {
ctx.StatusCode(iris.StatusInternalServerError)
ctx.Writef(err.Error())
ctx.WriteString(err.Error())
}
})
@@ -29,7 +33,7 @@ func main() {
ctx.ViewLayout(iris.NoLayout)
if err := ctx.View("page1.html"); err != nil {
ctx.StatusCode(iris.StatusInternalServerError)
ctx.Writef(err.Error())
ctx.WriteString(err.Error())
}
})
@@ -38,13 +42,13 @@ func main() {
{ // both of these will use the layouts/mylayout.html as their layout.
my.Get("/", func(ctx iris.Context) {
if err := ctx.View("page1.html"); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
})
my.Get("/other", func(ctx iris.Context) {
if err := ctx.View("page1.html"); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
})

View File

@@ -2,6 +2,7 @@ package main
import (
"embed"
"fmt"
"github.com/kataras/iris/v12"
)
@@ -23,7 +24,7 @@ func main() {
app.Get("/", func(ctx iris.Context) {
if err := ctx.View("page1.html"); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
})
@@ -32,7 +33,7 @@ func main() {
app.Get("/nolayout", func(ctx iris.Context) {
ctx.ViewLayout(iris.NoLayout)
if err := ctx.View("page1.html"); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
})
@@ -42,13 +43,13 @@ func main() {
{ // both of these will use the layouts/mylayout.html as their layout.
my.Get("/", func(ctx iris.Context) {
if err := ctx.View("page1.html"); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
})
my.Get("/other", func(ctx iris.Context) {
if err := ctx.View("page1.html"); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
})

View File

@@ -1,6 +1,10 @@
package main
import "github.com/kataras/iris/v12"
import (
"fmt"
"github.com/kataras/iris/v12"
)
func main() {
app := iris.New()
@@ -39,7 +43,7 @@ func main() {
func index(ctx iris.Context) {
if err := ctx.View("blabla.html"); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
}

View File

@@ -1,6 +1,10 @@
package main
import "github.com/kataras/iris/v12"
import (
"fmt"
"github.com/kataras/iris/v12"
)
func main() {
app := iris.New()
@@ -23,7 +27,7 @@ func index(ctx iris.Context) {
ctx.ViewLayout("layouts/main")
if err := ctx.View("index", data); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
}

View File

@@ -1,6 +1,10 @@
package main
import "github.com/kataras/iris/v12"
import (
"fmt"
"github.com/kataras/iris/v12"
)
func main() {
app := iris.New()
@@ -24,7 +28,7 @@ func index(ctx iris.Context) {
ctx.ViewLayout("main")
if err := ctx.View("index", data); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
}

View File

@@ -1,6 +1,10 @@
package main
import "github.com/kataras/iris/v12"
import (
"fmt"
"github.com/kataras/iris/v12"
)
func main() {
app := iris.New()
@@ -22,7 +26,7 @@ func index(ctx iris.Context) {
// Layouts are only rendered from inside the index page itself
// using the "extends" keyword.
if err := ctx.View("index", data); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
}

View File

@@ -1,6 +1,10 @@
package main
import "github.com/kataras/iris/v12"
import (
"fmt"
"github.com/kataras/iris/v12"
)
func main() {
app := iris.New()
@@ -21,7 +25,7 @@ func index(ctx iris.Context) {
ctx.ViewLayout("layouts/main")
if err := ctx.View("index", data); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
}

View File

@@ -1,6 +1,10 @@
package main
import "github.com/kataras/iris/v12"
import (
"fmt"
"github.com/kataras/iris/v12"
)
func main() {
app := iris.New()
@@ -21,7 +25,7 @@ func index(ctx iris.Context) {
ctx.ViewLayout("layouts/main")
if err := ctx.View("index", data); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
}

View File

@@ -1,6 +1,10 @@
package main
import "github.com/kataras/iris/v12"
import (
"fmt"
"github.com/kataras/iris/v12"
)
func main() {
app := iris.New()
@@ -23,7 +27,7 @@ func index(ctx iris.Context) {
// Layouts are only rendered from inside the index page itself
// using the "extends" keyword.
if err := ctx.View("index", data); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
}

View File

@@ -1,6 +1,10 @@
package main
import "github.com/kataras/iris/v12"
import (
"fmt"
"github.com/kataras/iris/v12"
)
func main() {
app := iris.New()
@@ -22,7 +26,7 @@ func index(ctx iris.Context) {
// Layouts are only rendered from inside the index page itself
// using the "extends" keyword.
if err := ctx.View("index", data); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
}

View File

@@ -1,6 +1,7 @@
package main
import (
"fmt"
"html/template"
"time"
@@ -36,7 +37,7 @@ func main() {
// render the template with the file name relative to the './templates'.
// file extension is OPTIONAL.
if err := ctx.View("hi.html"); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
})
@@ -51,7 +52,7 @@ func main() {
}
if err := ctx.View("example.html", examplePage); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
})
@@ -80,7 +81,7 @@ func main() {
}
if err := ctx.View("example.html", examplePage); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
})
@@ -97,7 +98,7 @@ func main() {
}
if err := ctx.View("functions.html", functionsPage); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
})

View File

@@ -1,6 +1,10 @@
package main
import "github.com/kataras/iris/v12"
import (
"fmt"
"github.com/kataras/iris/v12"
)
func main() {
e := iris.Django(nil, ".html") // You can still use a file system though.
@@ -24,7 +28,7 @@ func index(ctx iris.Context) {
if err := ctx.View("program.html", iris.Map{
"Name": "Gerasimos",
}); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
}

View File

@@ -1,6 +1,10 @@
package main
import "github.com/kataras/iris/v12"
import (
"fmt"
"github.com/kataras/iris/v12"
)
func main() {
e := iris.Handlebars(nil, ".html") // You can still use a file system though.
@@ -22,7 +26,7 @@ func index(ctx iris.Context) {
if err := ctx.View("program.html", iris.Map{
"Name": "Gerasimos",
}); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
}

View File

@@ -1,6 +1,7 @@
package main
import (
"fmt"
"reflect"
"github.com/kataras/iris/v12"
@@ -30,7 +31,7 @@ func index(ctx iris.Context) {
if err := ctx.View("program.jet", iris.Map{
"Name": "Gerasimos",
}); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
}

View File

@@ -4,7 +4,11 @@
// template parsers navigate through the example's subdirectories.
package main
import "github.com/kataras/iris/v12"
import (
"fmt"
"github.com/kataras/iris/v12"
)
func main() {
// To not load any templates from files or embedded data,
@@ -34,7 +38,7 @@ func index(ctx iris.Context) {
if err := ctx.View("program.html", iris.Map{
"Name": "Gerasimos",
}); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
}

View File

@@ -1,6 +1,10 @@
package main
import "github.com/kataras/iris/v12"
import (
"fmt"
"github.com/kataras/iris/v12"
)
func main() {
app := iris.New()
@@ -15,7 +19,7 @@ func main() {
if err := ctx.View("index", iris.Map{
"Title": "Title of The Page",
}); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
})
@@ -25,7 +29,7 @@ func main() {
if err := ctx.View("index", iris.Map{ // file extension is optional.
"Title": "Title of the main Page",
}); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
})

View File

@@ -1,6 +1,10 @@
package main
import "github.com/kataras/iris/v12"
import (
"fmt"
"github.com/kataras/iris/v12"
)
func main() {
app := iris.New()
@@ -20,7 +24,7 @@ func index(ctx iris.Context) {
ctx.ViewLayout("main")
if err := ctx.View("index", data); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
}
@@ -35,7 +39,7 @@ func internalServerError(ctx iris.Context) {
ctx.ViewLayout("error")
if err := ctx.View("500", data); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
}

View File

@@ -1,6 +1,10 @@
package main
import "github.com/kataras/iris/v12"
import (
"fmt"
"github.com/kataras/iris/v12"
)
// $ go install github.com/go-bindata/go-bindata/v3/go-bindata@latest
//
@@ -29,7 +33,7 @@ func index(ctx iris.Context) {
ctx.ViewLayout("main")
if err := ctx.View("index", data); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
}
@@ -44,7 +48,7 @@ func internalServerError(ctx iris.Context) {
ctx.ViewLayout("error")
if err := ctx.View("500", data); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
}

View File

@@ -1,6 +1,7 @@
package main
import (
"fmt"
"time"
"github.com/kataras/iris/v12"
@@ -40,7 +41,7 @@ func hi(ctx iris.Context) {
"name": "iris",
"serverStartTime": startTime,
}); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
}

View File

@@ -1,6 +1,10 @@
package main
import "github.com/kataras/iris/v12"
import (
"fmt"
"github.com/kataras/iris/v12"
)
func main() {
app := iris.New()
@@ -31,7 +35,7 @@ func main() {
paramsAsArray := []string{"theParam1", "theParam2", "paramThirdAfterStatic"}
ctx.ViewData("ParamsAsArray", paramsAsArray)
if err := ctx.View("page.html"); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
})

View File

@@ -1,6 +1,8 @@
package main
import (
"fmt"
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/mvc"
)
@@ -29,7 +31,7 @@ func main() {
}
if err := ctx.View("example.html", viewData); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
})

View File

@@ -1,6 +1,8 @@
package main
import (
"fmt"
"github.com/kataras/iris/v12"
)
@@ -32,7 +34,7 @@ func hi(ctx iris.Context) {
ctx.ViewData("Name", "iris") // {{.Name}} will render: iris
// ctx.ViewData("", myCcustomStruct{})
if err := ctx.View("hi.html"); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
}

View File

@@ -1,6 +1,8 @@
package main
import (
"fmt"
"github.com/kataras/iris/v12"
)
@@ -19,7 +21,7 @@ func main() {
ctx.CompressWriter(true)
ctx.ViewData("", mypage{"My Page title", "Hello world!"})
if err := ctx.View("mypage.html"); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
// Note that: you can pass "layout" : "otherLayout.html" to bypass the config's Layout property

View File

@@ -1,6 +1,8 @@
package main
import (
"fmt"
"github.com/kataras/iris/v12"
)
@@ -18,7 +20,7 @@ func main() {
app.Get("/", func(ctx iris.Context) {
if err := ctx.View("page1.html"); err != nil {
ctx.StatusCode(iris.StatusInternalServerError)
ctx.Writef(err.Error())
ctx.WriteString(err.Error())
}
})
@@ -27,7 +29,7 @@ func main() {
ctx.ViewLayout(iris.NoLayout)
if err := ctx.View("page1.html"); err != nil {
ctx.StatusCode(iris.StatusInternalServerError)
ctx.Writef(err.Error())
ctx.WriteString(err.Error())
}
})
@@ -36,13 +38,13 @@ func main() {
{ // both of these will use the layouts/mylayout.html as their layout.
my.Get("/", func(ctx iris.Context) {
if err := ctx.View("page1.html"); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
})
my.Get("/other", func(ctx iris.Context) {
if err := ctx.View("page1.html"); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
})

View File

@@ -3,6 +3,8 @@
package main
import (
"fmt"
"github.com/kataras/iris/v12"
)
@@ -35,7 +37,7 @@ func main() {
paramsAsArray := []string{"theParam1", "theParam2", "paramThirdAfterStatic"}
ctx.ViewData("ParamsAsArray", paramsAsArray)
if err := ctx.View("page.html"); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
})

View File

@@ -2,6 +2,8 @@
package main
import (
"fmt"
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/core/router"
)
@@ -52,7 +54,7 @@ func main() {
paramsAsArray := []string{"username5", "theParam1", "theParam2", "paramThirdAfterStatic"}
ctx.ViewData("ParamsAsArray", paramsAsArray)
if err := ctx.View("page.html"); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
})

View File

@@ -1,6 +1,8 @@
package main
import (
"fmt"
"github.com/kataras/iris/v12"
)
@@ -13,7 +15,7 @@ func main() {
app.Get("/home", func(ctx iris.Context) {
ctx.ViewData("title", "Home page")
if err := ctx.View("home.html"); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
@@ -24,14 +26,14 @@ func main() {
app.Get("/about", func(ctx iris.Context) {
if err := ctx.View("about.html"); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
})
app.Get("/user/index", func(ctx iris.Context) {
if err := ctx.View("user/index.html"); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
})

View File

@@ -114,7 +114,7 @@ func main() {
ctx.ViewData("title", "Show TODO")
if err := ctx.View("todos/show.jet", todo); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
})
@@ -136,7 +136,7 @@ func main() {
// and ctx.View("todos/index.jet")
// OR
if err := ctx.View("todos/index.jet", (&doneTODOs{}).New(todos)); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
})

View File

@@ -5,6 +5,7 @@
package main
import (
"fmt"
"os"
"github.com/kataras/iris/v12"
@@ -23,7 +24,7 @@ func main() {
app.Get("/", func(ctx iris.Context) {
if err := ctx.View("index.jet"); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
})

View File

@@ -2,6 +2,8 @@
package main
import (
"fmt"
"github.com/kataras/iris/v12"
)
@@ -34,7 +36,7 @@ func main() {
paramsAsArray := []string{"theParam1", "theParam2", "paramThirdAfterStatic"}
ctx.ViewData("ParamsAsArray", paramsAsArray)
if err := ctx.View("page.jet"); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
})

View File

@@ -25,7 +25,7 @@ func main() {
app.Get("/", func(ctx iris.Context) {
if err := ctx.View("index.jet"); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
})

View File

@@ -1,7 +1,11 @@
// Package main shows an example of pug actions based on https://github.com/Joker/jade/tree/master/example/actions
package main
import "github.com/kataras/iris/v12"
import (
"fmt"
"github.com/kataras/iris/v12"
)
type Person struct {
Name string
@@ -39,7 +43,7 @@ func index(ctx iris.Context) {
}
if err := ctx.View("index.pug", person); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
}

View File

@@ -1,6 +1,7 @@
package main
import (
"fmt"
"html/template"
"github.com/kataras/iris/v12"
@@ -25,7 +26,7 @@ func main() {
func index(ctx iris.Context) {
if err := ctx.View("index.pug"); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
}

View File

@@ -1,6 +1,10 @@
package main
import "github.com/kataras/iris/v12"
import (
"fmt"
"github.com/kataras/iris/v12"
)
// $ go install github.com/go-bindata/go-bindata/v3/go-bindata@latest
//
@@ -23,7 +27,7 @@ func main() {
func index(ctx iris.Context) {
if err := ctx.View("index.pug"); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
}