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:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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("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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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("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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
})
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
})
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
})
|
||||
|
||||
@@ -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
|
||||
}
|
||||
})
|
||||
|
||||
@@ -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
|
||||
}
|
||||
})
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
})
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
})
|
||||
|
||||
@@ -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
|
||||
}
|
||||
})
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
})
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
})
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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...))
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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>")
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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>")
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
})
|
||||
|
||||
@@ -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
|
||||
}
|
||||
})
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
})
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
})
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
})
|
||||
|
||||
@@ -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
|
||||
}
|
||||
})
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
})
|
||||
|
||||
@@ -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
|
||||
}
|
||||
})
|
||||
|
||||
@@ -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
|
||||
}
|
||||
})
|
||||
|
||||
@@ -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
|
||||
}
|
||||
})
|
||||
|
||||
@@ -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
|
||||
}
|
||||
})
|
||||
|
||||
@@ -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
|
||||
}
|
||||
})
|
||||
|
||||
@@ -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
|
||||
}
|
||||
})
|
||||
|
||||
@@ -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
|
||||
}
|
||||
})
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
})
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -792,9 +792,9 @@ func (ctx *Context) StopWithStatus(statusCode int) {
|
||||
//
|
||||
// If the status code is a failure one then
|
||||
// it will also fire the specified error code handler.
|
||||
func (ctx *Context) StopWithText(statusCode int, format string, args ...interface{}) {
|
||||
func (ctx *Context) StopWithText(statusCode int, text string) {
|
||||
ctx.StopWithStatus(statusCode)
|
||||
ctx.WriteString(fmt.Sprintf(format, args...))
|
||||
ctx.WriteString(text)
|
||||
}
|
||||
|
||||
// StopWithError stops the handlers chain and writes the "statusCode"
|
||||
@@ -4034,15 +4034,15 @@ func (ctx *Context) Binary(data []byte) (int, error) {
|
||||
}
|
||||
|
||||
// Text writes out a string as plain text.
|
||||
func (ctx *Context) Text(format string, args ...interface{}) (int, error) {
|
||||
func (ctx *Context) Text(text string) (int, error) {
|
||||
ctx.ContentType(ContentTextHeaderValue)
|
||||
return ctx.Writef(format, args...)
|
||||
return ctx.WriteString(text)
|
||||
}
|
||||
|
||||
// HTML writes out a string as text/html.
|
||||
func (ctx *Context) HTML(format string, args ...interface{}) (int, error) {
|
||||
func (ctx *Context) HTML(text string) (int, error) {
|
||||
ctx.ContentType(ContentHTMLHeaderValue)
|
||||
return ctx.Writef(format, args...)
|
||||
return ctx.WriteString(text)
|
||||
}
|
||||
|
||||
// ProtoMarshalOptions is a type alias for protojson.MarshalOptions.
|
||||
|
||||
@@ -1804,7 +1804,7 @@ func (api *APIBuilder) FallbackView(provider context.FallbackViewProvider) {
|
||||
//
|
||||
// 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
|
||||
// }
|
||||
// })
|
||||
|
||||
@@ -466,7 +466,7 @@ type Party interface {
|
||||
// my := app.Party("/my").Layout("layouts/mylayout.html")
|
||||
// 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
|
||||
// }
|
||||
// })
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package router_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
@@ -200,7 +201,7 @@ func TestNewSubdomainPartyRedirectHandler(t *testing.T) {
|
||||
func TestHandleServer(t *testing.T) {
|
||||
otherApp := iris.New()
|
||||
otherApp.Get("/test/me/{first:string}", func(ctx iris.Context) {
|
||||
ctx.HTML("<h1>Other App: %s</h1>", ctx.Params().Get("first"))
|
||||
ctx.HTML(fmt.Sprintf("<h1>Other App: %s</h1>", ctx.Params().Get("first")))
|
||||
})
|
||||
otherApp.Build()
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ var h2 = func(ctx *context.Context) {
|
||||
}
|
||||
|
||||
func h3(ctx *context.Context) {
|
||||
ctx.Writef(staticPathPrefixBody + ctx.Path())
|
||||
ctx.WriteString(staticPathPrefixBody + ctx.Path())
|
||||
}
|
||||
|
||||
func TestRouterWildcardDifferentPrefixPath(t *testing.T) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package hero_test
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
@@ -111,9 +112,9 @@ func TestDependentDependency(t *testing.T) {
|
||||
},
|
||||
{ // 3
|
||||
Dependency: func(msg testMessage) error {
|
||||
return fmt.Errorf(msg.Body)
|
||||
return errors.New(msg.Body)
|
||||
},
|
||||
Expected: fmt.Errorf(msgBody),
|
||||
Expected: errors.New(msgBody),
|
||||
},
|
||||
// Test depend on more than one previous registered dependencies and require a before-previous one.
|
||||
{ // 4
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package parser
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -101,7 +102,7 @@ const (
|
||||
|
||||
func (p ParamParser) Error() error {
|
||||
if len(p.errors) > 0 {
|
||||
return fmt.Errorf(strings.Join(p.errors, "\n"))
|
||||
return errors.New(strings.Join(p.errors, "\n"))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ func DefaultErrorHandler(ctx *context.Context, err error) {
|
||||
unauthorize(ctx, e.AuthenticateHeader, e.AuthenticateHeaderValue, e.Code)
|
||||
default:
|
||||
// This will never happen.
|
||||
ctx.StopWithText(http.StatusInternalServerError, "unknown error: %v", err)
|
||||
ctx.StopWithText(http.StatusInternalServerError, fmt.Sprintf("unknown error: %v", err))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,9 @@ import (
|
||||
|
||||
"github.com/kataras/iris/v12/core/router"
|
||||
"github.com/kataras/iris/v12/macro"
|
||||
|
||||
"golang.org/x/text/cases"
|
||||
"golang.org/x/text/language"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -137,8 +140,8 @@ func parseMethod(macros *macro.Macros, fn reflect.Method, skipper func(string) b
|
||||
}
|
||||
|
||||
func methodTitle(httpMethod string) string {
|
||||
httpMethodFuncName := strings.Title(strings.ToLower(httpMethod))
|
||||
return httpMethodFuncName
|
||||
caser := cases.Title(language.English)
|
||||
return caser.String(strings.ToLower(httpMethod))
|
||||
}
|
||||
|
||||
var errSkip = errors.New("skip")
|
||||
|
||||
@@ -19,7 +19,7 @@ type testController struct {
|
||||
}
|
||||
|
||||
var writeMethod = func(ctx *context.Context) {
|
||||
ctx.Writef(ctx.Method())
|
||||
ctx.WriteString(ctx.Method())
|
||||
}
|
||||
|
||||
func (c *testController) Get() {
|
||||
@@ -108,15 +108,15 @@ func (c *testControllerBeginAndEndRequestFunc) BeginRequest(ctx *context.Context
|
||||
|
||||
// called after every method (Get() or Post()).
|
||||
func (c *testControllerBeginAndEndRequestFunc) EndRequest(ctx *context.Context) {
|
||||
ctx.Writef("done") // append "done" to the response
|
||||
ctx.WriteString("done") // append "done" to the response
|
||||
}
|
||||
|
||||
func (c *testControllerBeginAndEndRequestFunc) Get() {
|
||||
c.Ctx.Writef(c.Username)
|
||||
c.Ctx.WriteString(c.Username)
|
||||
}
|
||||
|
||||
func (c *testControllerBeginAndEndRequestFunc) Post() {
|
||||
c.Ctx.Writef(c.Username)
|
||||
c.Ctx.WriteString(c.Username)
|
||||
}
|
||||
|
||||
func TestControllerBeginAndEndRequestFunc(t *testing.T) {
|
||||
@@ -230,7 +230,7 @@ func writeModels(ctx *context.Context, names ...string) {
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Writef(model.Username)
|
||||
ctx.WriteString(model.Username)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -269,7 +269,7 @@ type testControllerBindStruct struct {
|
||||
}
|
||||
|
||||
func (t *testControllerBindStruct) Get() {
|
||||
t.Ctx.Writef(t.TitlePointer.title + t.TitleValue.title + t.Other)
|
||||
t.Ctx.WriteString(t.TitlePointer.title + t.TitleValue.title + t.Other)
|
||||
}
|
||||
|
||||
// test if context can be binded to the controller's function
|
||||
@@ -291,7 +291,7 @@ func (t *testControllerBindDeep) BeforeActivation(b BeforeActivation) {
|
||||
|
||||
func (t *testControllerBindDeep) Get() {
|
||||
// t.testControllerBindStruct.Get()
|
||||
t.Ctx.Writef(t.TitlePointer.title + t.TitleValue.title + t.Other)
|
||||
t.Ctx.WriteString(t.TitlePointer.title + t.TitleValue.title + t.Other)
|
||||
}
|
||||
|
||||
func (t *testControllerBindDeep) Post(v testCustomStruct) string {
|
||||
@@ -338,9 +338,9 @@ func (c *testCtrl0) Get() string {
|
||||
|
||||
func (c *testCtrl0) EndRequest(ctx *context.Context) {
|
||||
if c.TitlePointer == nil {
|
||||
ctx.Writef("\nTitlePointer is nil!\n")
|
||||
ctx.WriteString("\nTitlePointer is nil!\n")
|
||||
} else {
|
||||
ctx.Writef(c.TitlePointer.title)
|
||||
ctx.WriteString(c.TitlePointer.title)
|
||||
}
|
||||
|
||||
// should be the same as `.testCtrl000.testCtrl0000.EndRequest(ctx)`
|
||||
|
||||
@@ -93,7 +93,7 @@ func testSessions(t *testing.T, app *iris.Application) {
|
||||
ctx.Next()
|
||||
}, func(ctx *context.Context) {
|
||||
s := sessions.Get(ctx)
|
||||
_, err := ctx.Writef(s.GetString("key"))
|
||||
_, err := ctx.WriteString(s.GetString("key"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ func main() {
|
||||
ctx.ViewData("message", "Hello world!")
|
||||
// Render template file: ./views/hello.html
|
||||
if err := ctx.View("hello.html"); err != nil {
|
||||
ctx.HTML("<h3>%s</h3>", err.Error())
|
||||
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
|
||||
return
|
||||
}
|
||||
})
|
||||
@@ -109,7 +109,7 @@ func main() {
|
||||
func hi(ctx iris.Context) {
|
||||
// render the template file "./templates/hi.html"
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -156,7 +156,7 @@ func hi(ctx iris.Context) {
|
||||
// {{.Page.Title}} and {{Page.Name}}
|
||||
ctx.ViewData("Page", page{Title: "Hi Page", Name: "iris"})
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -271,13 +271,13 @@ func (e ErrorCodeName) MapErrors(targets ...error) {
|
||||
}
|
||||
|
||||
// Message sends an error with a simple message to the client.
|
||||
func (e ErrorCodeName) Message(ctx *context.Context, format string, args ...interface{}) {
|
||||
fail(ctx, e, sprintf(format, args...), "", nil, nil)
|
||||
func (e ErrorCodeName) Message(ctx *context.Context, msg string) {
|
||||
fail(ctx, e, msg, "", nil, nil)
|
||||
}
|
||||
|
||||
// Details sends an error with a message and details to the client.
|
||||
func (e ErrorCodeName) Details(ctx *context.Context, msg, details string, detailsArgs ...interface{}) {
|
||||
fail(ctx, e, msg, sprintf(details, detailsArgs...), nil, nil)
|
||||
func (e ErrorCodeName) Details(ctx *context.Context, msg, details string) {
|
||||
fail(ctx, e, msg, msg, nil, nil)
|
||||
}
|
||||
|
||||
// Data sends an error with a message and json data to the client.
|
||||
@@ -419,7 +419,7 @@ func handleJSONError(ctx *context.Context, err error) bool {
|
||||
|
||||
var syntaxErr *json.SyntaxError
|
||||
if errors.As(err, &syntaxErr) {
|
||||
wireError.Details(ctx, messageText, "json: syntax error at byte offset %d", syntaxErr.Offset)
|
||||
wireError.Details(ctx, messageText, fmt.Sprintf("json: syntax error at byte offset %d", syntaxErr.Offset))
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
@@ -220,7 +220,7 @@ func Validation[T any](validators ...ContextRequestFunc[T]) context.Handler {
|
||||
return nil
|
||||
}
|
||||
|
||||
validator := joinContextRequestFuncs[T](validators)
|
||||
validator := joinContextRequestFuncs(validators)
|
||||
|
||||
return func(ctx *context.Context) {
|
||||
ctx.Values().Set(contextRequestHandlerFuncKey, validator)
|
||||
@@ -322,7 +322,7 @@ func Intercept[T, R any](responseHandlers ...ContextResponseFunc[T, R]) context.
|
||||
return nil
|
||||
}
|
||||
|
||||
responseHandler := joinContextResponseFuncs[T, R](responseHandlers)
|
||||
responseHandler := joinContextResponseFuncs(responseHandlers)
|
||||
|
||||
return func(ctx *context.Context) {
|
||||
ctx.Values().Set(contextResponseHandlerFuncKey, responseHandler)
|
||||
|
||||
Reference in New Issue
Block a user