1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-17 09:57:01 +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

@@ -119,7 +119,7 @@ func main() {
func renderSigninForm(ctx iris.Context) {
if err := ctx.View("signin", iris.Map{"Title": "Signin Page"}); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
}

View File

@@ -21,6 +21,7 @@ package main
// are fixed in the time I wrote that example, have fun!
import (
"errors"
"fmt"
"os"
"sort"
@@ -380,7 +381,7 @@ func main() {
if err := ctx.View("user.html", iris.Map{
"user": user,
}); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
})
@@ -399,14 +400,14 @@ func main() {
}
if err := ctx.View("user.html", gothUser); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
})
app.Get("/", func(ctx iris.Context) {
if err := ctx.View("index.html", providerIndex); 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"
"os"
"github.com/kataras/iris/v12"
@@ -43,7 +44,7 @@ func register(ctx iris.Context) {
func registerForm(ctx iris.Context) {
ctx.ViewData("SiteKey", siteKey)
if err := ctx.View("register_form.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,7 @@
package bootstrap
import (
"fmt"
"time"
"github.com/gorilla/securecookie"
@@ -78,7 +79,7 @@ func (b *Bootstrapper) SetupErrorHandlers() {
ctx.ViewData("Err", err)
ctx.ViewData("Title", "Error")
if err := ctx.View("shared/error.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 routes
import (
"fmt"
"github.com/kataras/iris/v12"
)
@@ -8,7 +10,7 @@ import (
func GetIndexHandler(ctx iris.Context) {
ctx.ViewData("Title", "Index Page")
if err := ctx.View("index.html"); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
}

View File

@@ -107,7 +107,7 @@ func main() {
// GET: http://localhost:8080
app.Get("/", func(ctx iris.Context) {
if err := ctx.View("upload.html"); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
})

View File

@@ -172,7 +172,7 @@ func main() {
app.Get("/", func(ctx iris.Context) {
if err := ctx.View("upload.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,7 @@
package main
import (
"fmt"
"image/jpeg"
"image/png"
"io"
@@ -125,7 +126,7 @@ func main() {
app.Get("/", func(ctx iris.Context) {
if err := ctx.View("upload.html"); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
})

View File

@@ -95,7 +95,7 @@ func uploadView(ctx iris.Context) {
token := fmt.Sprintf("%x", h.Sum(nil))
if err := ctx.View("upload.html", token); 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"
)
@@ -27,7 +29,7 @@ func newApp() *iris.Application {
app.Get("/", func(ctx iris.Context) {
ctx.ViewData("Page", page)
if err := ctx.View("index.html"); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
})

View File

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

View File

@@ -32,7 +32,7 @@ func main() {
// or add second argument to the `View` method.
// Token will be passed as {{.}} in the template.
if err := ctx.View("upload_form.html", token); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
})

View File

@@ -33,7 +33,7 @@ func newApp() *iris.Application {
// render the form with the token for any use you'd like.
if err := ctx.View("upload_form.html", token); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
})

View File

@@ -87,7 +87,7 @@ func newApp() *iris.Application {
return template.HTML(ctx.Tr(message, args...))
},
}); 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"
"os"
"github.com/kataras/iris/v12"
@@ -62,7 +63,7 @@ func notFoundHandler(ctx iris.Context) {
ctx.HTML("Did you mean?<ul>")
for _, s := range suggestPaths {
ctx.HTML(`<li><a href="%s">%s</a></li>`, s, s)
ctx.HTML(fmt.Sprintf(`<li><a href="%s">%s</a></li>`, s, s))
}
ctx.HTML("</ul>")
}
@@ -73,7 +74,7 @@ func indexHandler(ctx iris.Context) {
func profileHandler(ctx iris.Context) {
username := ctx.Params().Get("username")
ctx.HTML("Hello, <strong>%s</strong>!", username)
ctx.HTML(fmt.Sprintf("Hello, <strong>%s</strong>!", username))
}
func readBodyHandler(ctx iris.Context) {

View File

@@ -3,6 +3,7 @@
package main
import (
"fmt"
"time"
"github.com/kataras/iris/v12/_examples/mvc/login/datasource"
@@ -34,7 +35,7 @@ func main() {
ctx.ViewData("Message", ctx.Values().
GetStringDefault("message", "The page you're looking for doesn't exist"))
if err := ctx.View("shared/error.html"); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
})

View File

@@ -52,7 +52,7 @@ func newApp() *iris.Application {
func renderSigninForm(ctx iris.Context) {
if err := ctx.View("signin", iris.Map{"Title": "Signin 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()
@@ -14,7 +18,7 @@ func main() {
func showForm(ctx iris.Context) {
if err := ctx.View("form.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"
)
@@ -19,7 +21,7 @@ func main() {
app.Get("/", func(ctx iris.Context) {
if err := ctx.View("form.html"); 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"
"net/http"
"github.com/kataras/iris/v12"
@@ -39,7 +40,7 @@ func pushHandler(ctx iris.Context) {
}
}
ctx.HTML(`<html><body><script src="%s"></script></body></html>`, target)
ctx.HTML(fmt.Sprintf(`<html><body><script src="%s"></script></body></html>`, target))
}
func simpleAssetHandler(ctx iris.Context) {

View File

@@ -1,6 +1,7 @@
package main
import (
"fmt"
"sync"
"github.com/kataras/iris/v12"
@@ -82,5 +83,5 @@ func (c *myCustomContext) SetContext(ctx iris.Context) {
func (c *myCustomContext) HTML(format string, args ...interface{}) (int, error) {
c.Application().Logger().Info("HTML was called from custom Context")
return c.Context.HTML(format, args...)
return c.Context.HTML(fmt.Sprintf(format, args...))
}

View File

@@ -1,6 +1,8 @@
package main
import (
"fmt"
"github.com/kataras/iris/v12"
// IMPORTANT, import this sub-package.
// Note tht it does NOT break compatibility with the
@@ -49,7 +51,7 @@ func main() {
}
func fireCustomErrorCodeName(ctx iris.Context) {
Custom.Details(ctx, "message", "details with arguments: %s", "an argument")
Custom.Details(ctx, "message", fmt.Sprintf("details with arguments: %s", "an argument"))
}
func fireInvalidArgument(ctx iris.Context) {

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()
@@ -27,7 +31,7 @@ func notFound(ctx iris.Context) {
ctx.HTML("Did you mean?<ul>")
for _, s := range suggestPaths {
ctx.HTML(`<li><a href="%s">%s</a></li>`, s, s)
ctx.HTML(fmt.Sprintf(`<li><a href="%s">%s</a></li>`, s, s))
}
ctx.HTML("</ul>")
}

View File

@@ -111,7 +111,7 @@ func newApp() *iris.Application {
// if is larger then send a bad request status
if err != nil {
ctx.StatusCode(iris.StatusBadRequest)
ctx.Writef(err.Error())
ctx.WriteString(err.Error())
return
}
// send back the post body

View File

@@ -1,6 +1,8 @@
package main
import (
"fmt"
"github.com/kataras/iris/v12"
)
@@ -77,7 +79,7 @@ func main() {
app.Get("/", func(ctx iris.Context) {
ctx.HTML("<html><head></head><body><ul>")
for _, link := range []string{"/encode", "/profile/username", "/users/42"} {
ctx.HTML(`<li><a href="%s">%s</a></li>`, link, link)
ctx.HTML(fmt.Sprintf(`<li><a href="%s">%s</a></li>`, link, link))
}
ctx.HTML("</ul></body></html>")
})
@@ -101,7 +103,7 @@ func profileByUsername(ctx iris.Context) {
// renders "./views/user/profile.html"
// with {{ .Username }} equals to the username dynamic path parameter.
if err := ctx.View("user/profile.html"); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
}
@@ -126,7 +128,7 @@ func createUser(ctx iris.Context) {
// with {{ . }} equals to the User object, i.e {{ .Username }} , {{ .Firstname}} etc...
ctx.ViewData("", user)
if err := ctx.View("user/create_verification.html"); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
}

View File

@@ -123,7 +123,7 @@ func main() {
app.Delete("/something", func(ctx iris.Context) {
name := ctx.URLParam("name")
ctx.Writef(name)
ctx.WriteString(name)
})
app.None("/secret", privateHandler)

View File

@@ -1,6 +1,10 @@
package main
import "github.com/kataras/iris/v12"
import (
"fmt"
"github.com/kataras/iris/v12"
)
func main() {
newApp().Listen("mydomain.com:80", iris.WithLogLevel("debug"))
@@ -31,7 +35,7 @@ func handleNotFoundTestSubdomain(ctx iris.Context) {
if err := ctx.View("error.html", iris.Map{
"ErrorCode": ctx.GetStatusCode(),
}); 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/versioning"
)
@@ -99,7 +101,7 @@ func testError(v string) iris.Handler {
func testView(ctx iris.Context) {
if err := ctx.View("index.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 example
import (
"errors"
"fmt"
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/sessions"
@@ -27,7 +28,7 @@ func NewApp(sess *sessions.Sessions) *iris.Application {
ctx.HTML("<ul>")
session.Visit(func(key string, value interface{}) {
ctx.HTML("<li> %s = %v </li>", key, value)
ctx.HTML(fmt.Sprintf("<li> %s = %v </li>", key, value))
})
ctx.HTML("</ul>")

View File

@@ -1,6 +1,8 @@
package main
import (
"fmt"
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/sessions"
)
@@ -30,7 +32,7 @@ func index(ctx iris.Context) {
session := sessions.Get(ctx)
session.Set("username", "kataras")
if err := ctx.View("index"); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
/* OR without middleware:

View File

@@ -10,6 +10,7 @@
package main
import (
"fmt"
"html/template"
"github.com/kataras/iris/v12"
@@ -51,7 +52,7 @@ func newApp(db *DB) *iris.Application {
indexHandler := func(ctx iris.Context) {
ctx.ViewData("URL_COUNT", db.Len())
if err := ctx.View("index.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()
@@ -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
}
}

View File

@@ -12,6 +12,7 @@ package main
import (
"flag"
"fmt"
"log"
"os"
"strconv"
@@ -147,7 +148,7 @@ func serveHome(ctx iris.Context) {
strconv.FormatInt(lastMod.UnixNano(), 16),
}
if err := ctx.View("home.html", v); 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"
"log"
"github.com/kataras/iris/v12"
@@ -50,7 +51,7 @@ func main() {
app.Get("/", func(ctx iris.Context) {
if err := ctx.View("client.html", clientPage{"Client Page", "localhost:8080"}); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
})

View File

@@ -34,7 +34,7 @@ func main() {
h := func(ctx iris.Context) {
ctx.ViewData("", page{PageID: "index page"})
if err := ctx.View("index.html"); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
}
@@ -42,7 +42,7 @@ func main() {
h2 := func(ctx iris.Context) {
ctx.ViewData("", page{PageID: "other page"})
if err := ctx.View("other.html"); err != nil {
ctx.HTML("<h3>%s</h3>", err.Error())
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
return
}
}