1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-20 03:17:04 +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,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
}
}