mirror of
https://github.com/kataras/iris.git
synced 2026-06-10 07:33:42 +00:00
update code for go version 1.24
This commit is contained in:
@@ -1,6 +1,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "github.com/kataras/iris/v12"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/kataras/iris/v12"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
app := iris.New()
|
app := iris.New()
|
||||||
@@ -21,7 +25,7 @@ func index(ctx iris.Context) {
|
|||||||
|
|
||||||
ctx.ViewLayout("layouts/main")
|
ctx.ViewLayout("layouts/main")
|
||||||
if err := ctx.View("index", data); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "github.com/kataras/iris/v12"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/kataras/iris/v12"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
app := iris.New()
|
app := iris.New()
|
||||||
@@ -23,7 +27,7 @@ func index(ctx iris.Context) {
|
|||||||
|
|
||||||
ctx.ViewLayout("main")
|
ctx.ViewLayout("main")
|
||||||
if err := ctx.View("index", data); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "github.com/kataras/iris/v12"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/kataras/iris/v12"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
app := iris.New()
|
app := iris.New()
|
||||||
@@ -22,7 +26,7 @@ func index(ctx iris.Context) {
|
|||||||
// Layouts are only rendered from inside the index page itself
|
// Layouts are only rendered from inside the index page itself
|
||||||
// using the "extends" keyword.
|
// using the "extends" keyword.
|
||||||
if err := ctx.View("index", data); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "github.com/kataras/iris/v12"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/kataras/iris/v12"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
app := iris.New()
|
app := iris.New()
|
||||||
@@ -20,7 +24,7 @@ func index(ctx iris.Context) {
|
|||||||
|
|
||||||
ctx.ViewLayout("layouts/main")
|
ctx.ViewLayout("layouts/main")
|
||||||
if err := ctx.View("index", data); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "github.com/kataras/iris/v12"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/kataras/iris/v12"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
app := iris.New()
|
app := iris.New()
|
||||||
@@ -21,7 +25,7 @@ func index(ctx iris.Context) {
|
|||||||
|
|
||||||
ctx.ViewLayout("layouts/main")
|
ctx.ViewLayout("layouts/main")
|
||||||
if err := ctx.View("index", data); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "github.com/kataras/iris/v12"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/kataras/iris/v12"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
app := iris.New()
|
app := iris.New()
|
||||||
@@ -22,7 +26,7 @@ func index(ctx iris.Context) {
|
|||||||
// Layouts are only rendered from inside the index page itself
|
// Layouts are only rendered from inside the index page itself
|
||||||
// using the "extends" keyword.
|
// using the "extends" keyword.
|
||||||
if err := ctx.View("index", data); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "github.com/kataras/iris/v12"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/kataras/iris/v12"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
app := iris.New()
|
app := iris.New()
|
||||||
@@ -23,7 +27,7 @@ func index(ctx iris.Context) {
|
|||||||
// Layouts are only rendered from inside the index page itself
|
// Layouts are only rendered from inside the index page itself
|
||||||
// using the "extends" keyword.
|
// using the "extends" keyword.
|
||||||
if err := ctx.View("index", data); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ func main() {
|
|||||||
|
|
||||||
func renderSigninForm(ctx iris.Context) {
|
func renderSigninForm(ctx iris.Context) {
|
||||||
if err := ctx.View("signin", iris.Map{"Title": "Signin Page"}); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ package main
|
|||||||
// are fixed in the time I wrote that example, have fun!
|
// are fixed in the time I wrote that example, have fun!
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
@@ -380,7 +381,7 @@ func main() {
|
|||||||
if err := ctx.View("user.html", iris.Map{
|
if err := ctx.View("user.html", iris.Map{
|
||||||
"user": user,
|
"user": user,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
ctx.HTML("<h3>%s</h3>", err.Error())
|
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -399,14 +400,14 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := ctx.View("user.html", gothUser); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
app.Get("/", func(ctx iris.Context) {
|
app.Get("/", func(ctx iris.Context) {
|
||||||
if err := ctx.View("index.html", providerIndex); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/kataras/iris/v12"
|
"github.com/kataras/iris/v12"
|
||||||
@@ -43,7 +44,7 @@ func register(ctx iris.Context) {
|
|||||||
func registerForm(ctx iris.Context) {
|
func registerForm(ctx iris.Context) {
|
||||||
ctx.ViewData("SiteKey", siteKey)
|
ctx.ViewData("SiteKey", siteKey)
|
||||||
if err := ctx.View("register_form.html"); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package bootstrap
|
package bootstrap
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gorilla/securecookie"
|
"github.com/gorilla/securecookie"
|
||||||
@@ -78,7 +79,7 @@ func (b *Bootstrapper) SetupErrorHandlers() {
|
|||||||
ctx.ViewData("Err", err)
|
ctx.ViewData("Err", err)
|
||||||
ctx.ViewData("Title", "Error")
|
ctx.ViewData("Title", "Error")
|
||||||
if err := ctx.View("shared/error.html"); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package routes
|
package routes
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/kataras/iris/v12"
|
"github.com/kataras/iris/v12"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -8,7 +10,7 @@ import (
|
|||||||
func GetIndexHandler(ctx iris.Context) {
|
func GetIndexHandler(ctx iris.Context) {
|
||||||
ctx.ViewData("Title", "Index Page")
|
ctx.ViewData("Title", "Index Page")
|
||||||
if err := ctx.View("index.html"); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ func main() {
|
|||||||
// GET: http://localhost:8080
|
// GET: http://localhost:8080
|
||||||
app.Get("/", func(ctx iris.Context) {
|
app.Get("/", func(ctx iris.Context) {
|
||||||
if err := ctx.View("upload.html"); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -172,7 +172,7 @@ func main() {
|
|||||||
|
|
||||||
app.Get("/", func(ctx iris.Context) {
|
app.Get("/", func(ctx iris.Context) {
|
||||||
if err := ctx.View("upload.html"); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"image/jpeg"
|
"image/jpeg"
|
||||||
"image/png"
|
"image/png"
|
||||||
"io"
|
"io"
|
||||||
@@ -125,7 +126,7 @@ func main() {
|
|||||||
|
|
||||||
app.Get("/", func(ctx iris.Context) {
|
app.Get("/", func(ctx iris.Context) {
|
||||||
if err := ctx.View("upload.html"); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ func uploadView(ctx iris.Context) {
|
|||||||
token := fmt.Sprintf("%x", h.Sum(nil))
|
token := fmt.Sprintf("%x", h.Sum(nil))
|
||||||
|
|
||||||
if err := ctx.View("upload.html", token); err != 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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-1
@@ -1,6 +1,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/kataras/iris/v12"
|
"github.com/kataras/iris/v12"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -27,7 +29,7 @@ func newApp() *iris.Application {
|
|||||||
app.Get("/", func(ctx iris.Context) {
|
app.Get("/", func(ctx iris.Context) {
|
||||||
ctx.ViewData("Page", page)
|
ctx.ViewData("Page", page)
|
||||||
if err := ctx.View("index.html"); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ func fullVueRouter() {
|
|||||||
|
|
||||||
func index(ctx iris.Context) {
|
func index(ctx iris.Context) {
|
||||||
if err := ctx.View("index.html"); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ func main() {
|
|||||||
// or add second argument to the `View` method.
|
// or add second argument to the `View` method.
|
||||||
// Token will be passed as {{.}} in the template.
|
// Token will be passed as {{.}} in the template.
|
||||||
if err := ctx.View("upload_form.html", token); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ func newApp() *iris.Application {
|
|||||||
|
|
||||||
// render the form with the token for any use you'd like.
|
// render the form with the token for any use you'd like.
|
||||||
if err := ctx.View("upload_form.html", token); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ func newApp() *iris.Application {
|
|||||||
return template.HTML(ctx.Tr(message, args...))
|
return template.HTML(ctx.Tr(message, args...))
|
||||||
},
|
},
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
ctx.HTML("<h3>%s</h3>", err.Error())
|
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/kataras/iris/v12"
|
"github.com/kataras/iris/v12"
|
||||||
@@ -62,7 +63,7 @@ func notFoundHandler(ctx iris.Context) {
|
|||||||
|
|
||||||
ctx.HTML("Did you mean?<ul>")
|
ctx.HTML("Did you mean?<ul>")
|
||||||
for _, s := range suggestPaths {
|
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>")
|
ctx.HTML("</ul>")
|
||||||
}
|
}
|
||||||
@@ -73,7 +74,7 @@ func indexHandler(ctx iris.Context) {
|
|||||||
|
|
||||||
func profileHandler(ctx iris.Context) {
|
func profileHandler(ctx iris.Context) {
|
||||||
username := ctx.Params().Get("username")
|
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) {
|
func readBodyHandler(ctx iris.Context) {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/kataras/iris/v12/_examples/mvc/login/datasource"
|
"github.com/kataras/iris/v12/_examples/mvc/login/datasource"
|
||||||
@@ -34,7 +35,7 @@ func main() {
|
|||||||
ctx.ViewData("Message", ctx.Values().
|
ctx.ViewData("Message", ctx.Values().
|
||||||
GetStringDefault("message", "The page you're looking for doesn't exist"))
|
GetStringDefault("message", "The page you're looking for doesn't exist"))
|
||||||
if err := ctx.View("shared/error.html"); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ func newApp() *iris.Application {
|
|||||||
|
|
||||||
func renderSigninForm(ctx iris.Context) {
|
func renderSigninForm(ctx iris.Context) {
|
||||||
if err := ctx.View("signin", iris.Map{"Title": "Signin Page"}); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "github.com/kataras/iris/v12"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/kataras/iris/v12"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
app := iris.New()
|
app := iris.New()
|
||||||
@@ -14,7 +18,7 @@ func main() {
|
|||||||
|
|
||||||
func showForm(ctx iris.Context) {
|
func showForm(ctx iris.Context) {
|
||||||
if err := ctx.View("form.html"); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/kataras/iris/v12"
|
"github.com/kataras/iris/v12"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -19,7 +21,7 @@ func main() {
|
|||||||
|
|
||||||
app.Get("/", func(ctx iris.Context) {
|
app.Get("/", func(ctx iris.Context) {
|
||||||
if err := ctx.View("form.html"); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/kataras/iris/v12"
|
"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) {
|
func simpleAssetHandler(ctx iris.Context) {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/kataras/iris/v12"
|
"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) {
|
func (c *myCustomContext) HTML(format string, args ...interface{}) (int, error) {
|
||||||
c.Application().Logger().Info("HTML was called from custom Context")
|
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
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/kataras/iris/v12"
|
"github.com/kataras/iris/v12"
|
||||||
// IMPORTANT, import this sub-package.
|
// IMPORTANT, import this sub-package.
|
||||||
// Note tht it does NOT break compatibility with the
|
// Note tht it does NOT break compatibility with the
|
||||||
@@ -49,7 +51,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func fireCustomErrorCodeName(ctx iris.Context) {
|
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) {
|
func fireInvalidArgument(ctx iris.Context) {
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "github.com/kataras/iris/v12"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/kataras/iris/v12"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
app := iris.New()
|
app := iris.New()
|
||||||
@@ -27,7 +31,7 @@ func notFound(ctx iris.Context) {
|
|||||||
|
|
||||||
ctx.HTML("Did you mean?<ul>")
|
ctx.HTML("Did you mean?<ul>")
|
||||||
for _, s := range suggestPaths {
|
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>")
|
ctx.HTML("</ul>")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ func newApp() *iris.Application {
|
|||||||
// if is larger then send a bad request status
|
// if is larger then send a bad request status
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.StatusCode(iris.StatusBadRequest)
|
ctx.StatusCode(iris.StatusBadRequest)
|
||||||
ctx.Writef(err.Error())
|
ctx.WriteString(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// send back the post body
|
// send back the post body
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/kataras/iris/v12"
|
"github.com/kataras/iris/v12"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -77,7 +79,7 @@ func main() {
|
|||||||
app.Get("/", func(ctx iris.Context) {
|
app.Get("/", func(ctx iris.Context) {
|
||||||
ctx.HTML("<html><head></head><body><ul>")
|
ctx.HTML("<html><head></head><body><ul>")
|
||||||
for _, link := range []string{"/encode", "/profile/username", "/users/42"} {
|
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>")
|
ctx.HTML("</ul></body></html>")
|
||||||
})
|
})
|
||||||
@@ -101,7 +103,7 @@ func profileByUsername(ctx iris.Context) {
|
|||||||
// renders "./views/user/profile.html"
|
// renders "./views/user/profile.html"
|
||||||
// with {{ .Username }} equals to the username dynamic path parameter.
|
// with {{ .Username }} equals to the username dynamic path parameter.
|
||||||
if err := ctx.View("user/profile.html"); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -126,7 +128,7 @@ func createUser(ctx iris.Context) {
|
|||||||
// with {{ . }} equals to the User object, i.e {{ .Username }} , {{ .Firstname}} etc...
|
// with {{ . }} equals to the User object, i.e {{ .Username }} , {{ .Firstname}} etc...
|
||||||
ctx.ViewData("", user)
|
ctx.ViewData("", user)
|
||||||
if err := ctx.View("user/create_verification.html"); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ func main() {
|
|||||||
|
|
||||||
app.Delete("/something", func(ctx iris.Context) {
|
app.Delete("/something", func(ctx iris.Context) {
|
||||||
name := ctx.URLParam("name")
|
name := ctx.URLParam("name")
|
||||||
ctx.Writef(name)
|
ctx.WriteString(name)
|
||||||
})
|
})
|
||||||
|
|
||||||
app.None("/secret", privateHandler)
|
app.None("/secret", privateHandler)
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "github.com/kataras/iris/v12"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/kataras/iris/v12"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
newApp().Listen("mydomain.com:80", iris.WithLogLevel("debug"))
|
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{
|
if err := ctx.View("error.html", iris.Map{
|
||||||
"ErrorCode": ctx.GetStatusCode(),
|
"ErrorCode": ctx.GetStatusCode(),
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
ctx.HTML("<h3>%s</h3>", err.Error())
|
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/kataras/iris/v12"
|
"github.com/kataras/iris/v12"
|
||||||
"github.com/kataras/iris/v12/versioning"
|
"github.com/kataras/iris/v12/versioning"
|
||||||
)
|
)
|
||||||
@@ -99,7 +101,7 @@ func testError(v string) iris.Handler {
|
|||||||
|
|
||||||
func testView(ctx iris.Context) {
|
func testView(ctx iris.Context) {
|
||||||
if err := ctx.View("index.html"); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package example
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/kataras/iris/v12"
|
"github.com/kataras/iris/v12"
|
||||||
"github.com/kataras/iris/v12/sessions"
|
"github.com/kataras/iris/v12/sessions"
|
||||||
@@ -27,7 +28,7 @@ func NewApp(sess *sessions.Sessions) *iris.Application {
|
|||||||
|
|
||||||
ctx.HTML("<ul>")
|
ctx.HTML("<ul>")
|
||||||
session.Visit(func(key string, value interface{}) {
|
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>")
|
ctx.HTML("</ul>")
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/kataras/iris/v12"
|
"github.com/kataras/iris/v12"
|
||||||
"github.com/kataras/iris/v12/sessions"
|
"github.com/kataras/iris/v12/sessions"
|
||||||
)
|
)
|
||||||
@@ -30,7 +32,7 @@ func index(ctx iris.Context) {
|
|||||||
session := sessions.Get(ctx)
|
session := sessions.Get(ctx)
|
||||||
session.Set("username", "kataras")
|
session.Set("username", "kataras")
|
||||||
if err := ctx.View("index"); err != nil {
|
if err := ctx.View("index"); err != nil {
|
||||||
ctx.HTML("<h3>%s</h3>", err.Error())
|
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
/* OR without middleware:
|
/* OR without middleware:
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
|
|
||||||
"github.com/kataras/iris/v12"
|
"github.com/kataras/iris/v12"
|
||||||
@@ -51,7 +52,7 @@ func newApp(db *DB) *iris.Application {
|
|||||||
indexHandler := func(ctx iris.Context) {
|
indexHandler := func(ctx iris.Context) {
|
||||||
ctx.ViewData("URL_COUNT", db.Len())
|
ctx.ViewData("URL_COUNT", db.Len())
|
||||||
if err := ctx.View("index.html"); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "github.com/kataras/iris/v12"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/kataras/iris/v12"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
app := iris.New()
|
app := iris.New()
|
||||||
@@ -38,7 +42,7 @@ func index(ctx iris.Context) {
|
|||||||
|
|
||||||
ctx.ViewLayout("main")
|
ctx.ViewLayout("main")
|
||||||
if err := ctx.View("index", data); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -50,7 +54,7 @@ func admin(ctx iris.Context) {
|
|||||||
|
|
||||||
ctx.ViewLayout("main")
|
ctx.ViewLayout("main")
|
||||||
if err := ctx.View("index", data); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -68,7 +72,7 @@ func onFly(ctx iris.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := ctx.View("index", data); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "github.com/kataras/iris/v12"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/kataras/iris/v12"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
app := iris.New()
|
app := iris.New()
|
||||||
@@ -20,7 +24,7 @@ func main() {
|
|||||||
app.Get("/", func(ctx iris.Context) {
|
app.Get("/", func(ctx iris.Context) {
|
||||||
if err := ctx.View("page1.html"); err != nil {
|
if err := ctx.View("page1.html"); err != nil {
|
||||||
ctx.StatusCode(iris.StatusInternalServerError)
|
ctx.StatusCode(iris.StatusInternalServerError)
|
||||||
ctx.Writef(err.Error())
|
ctx.WriteString(err.Error())
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -29,7 +33,7 @@ func main() {
|
|||||||
ctx.ViewLayout(iris.NoLayout)
|
ctx.ViewLayout(iris.NoLayout)
|
||||||
if err := ctx.View("page1.html"); err != nil {
|
if err := ctx.View("page1.html"); err != nil {
|
||||||
ctx.StatusCode(iris.StatusInternalServerError)
|
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.
|
{ // both of these will use the layouts/mylayout.html as their layout.
|
||||||
my.Get("/", func(ctx iris.Context) {
|
my.Get("/", func(ctx iris.Context) {
|
||||||
if err := ctx.View("page1.html"); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
my.Get("/other", func(ctx iris.Context) {
|
my.Get("/other", func(ctx iris.Context) {
|
||||||
if err := ctx.View("page1.html"); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"embed"
|
"embed"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/kataras/iris/v12"
|
"github.com/kataras/iris/v12"
|
||||||
)
|
)
|
||||||
@@ -23,7 +24,7 @@ func main() {
|
|||||||
|
|
||||||
app.Get("/", func(ctx iris.Context) {
|
app.Get("/", func(ctx iris.Context) {
|
||||||
if err := ctx.View("page1.html"); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -32,7 +33,7 @@ func main() {
|
|||||||
app.Get("/nolayout", func(ctx iris.Context) {
|
app.Get("/nolayout", func(ctx iris.Context) {
|
||||||
ctx.ViewLayout(iris.NoLayout)
|
ctx.ViewLayout(iris.NoLayout)
|
||||||
if err := ctx.View("page1.html"); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -42,13 +43,13 @@ func main() {
|
|||||||
{ // both of these will use the layouts/mylayout.html as their layout.
|
{ // both of these will use the layouts/mylayout.html as their layout.
|
||||||
my.Get("/", func(ctx iris.Context) {
|
my.Get("/", func(ctx iris.Context) {
|
||||||
if err := ctx.View("page1.html"); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
my.Get("/other", func(ctx iris.Context) {
|
my.Get("/other", func(ctx iris.Context) {
|
||||||
if err := ctx.View("page1.html"); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "github.com/kataras/iris/v12"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/kataras/iris/v12"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
app := iris.New()
|
app := iris.New()
|
||||||
@@ -39,7 +43,7 @@ func main() {
|
|||||||
|
|
||||||
func index(ctx iris.Context) {
|
func index(ctx iris.Context) {
|
||||||
if err := ctx.View("blabla.html"); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "github.com/kataras/iris/v12"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/kataras/iris/v12"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
app := iris.New()
|
app := iris.New()
|
||||||
@@ -23,7 +27,7 @@ func index(ctx iris.Context) {
|
|||||||
|
|
||||||
ctx.ViewLayout("layouts/main")
|
ctx.ViewLayout("layouts/main")
|
||||||
if err := ctx.View("index", data); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "github.com/kataras/iris/v12"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/kataras/iris/v12"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
app := iris.New()
|
app := iris.New()
|
||||||
@@ -24,7 +28,7 @@ func index(ctx iris.Context) {
|
|||||||
|
|
||||||
ctx.ViewLayout("main")
|
ctx.ViewLayout("main")
|
||||||
if err := ctx.View("index", data); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "github.com/kataras/iris/v12"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/kataras/iris/v12"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
app := iris.New()
|
app := iris.New()
|
||||||
@@ -22,7 +26,7 @@ func index(ctx iris.Context) {
|
|||||||
// Layouts are only rendered from inside the index page itself
|
// Layouts are only rendered from inside the index page itself
|
||||||
// using the "extends" keyword.
|
// using the "extends" keyword.
|
||||||
if err := ctx.View("index", data); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "github.com/kataras/iris/v12"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/kataras/iris/v12"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
app := iris.New()
|
app := iris.New()
|
||||||
@@ -21,7 +25,7 @@ func index(ctx iris.Context) {
|
|||||||
|
|
||||||
ctx.ViewLayout("layouts/main")
|
ctx.ViewLayout("layouts/main")
|
||||||
if err := ctx.View("index", data); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "github.com/kataras/iris/v12"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/kataras/iris/v12"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
app := iris.New()
|
app := iris.New()
|
||||||
@@ -21,7 +25,7 @@ func index(ctx iris.Context) {
|
|||||||
|
|
||||||
ctx.ViewLayout("layouts/main")
|
ctx.ViewLayout("layouts/main")
|
||||||
if err := ctx.View("index", data); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "github.com/kataras/iris/v12"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/kataras/iris/v12"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
app := iris.New()
|
app := iris.New()
|
||||||
@@ -23,7 +27,7 @@ func index(ctx iris.Context) {
|
|||||||
// Layouts are only rendered from inside the index page itself
|
// Layouts are only rendered from inside the index page itself
|
||||||
// using the "extends" keyword.
|
// using the "extends" keyword.
|
||||||
if err := ctx.View("index", data); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "github.com/kataras/iris/v12"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/kataras/iris/v12"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
app := iris.New()
|
app := iris.New()
|
||||||
@@ -22,7 +26,7 @@ func index(ctx iris.Context) {
|
|||||||
// Layouts are only rendered from inside the index page itself
|
// Layouts are only rendered from inside the index page itself
|
||||||
// using the "extends" keyword.
|
// using the "extends" keyword.
|
||||||
if err := ctx.View("index", data); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -36,7 +37,7 @@ func main() {
|
|||||||
// render the template with the file name relative to the './templates'.
|
// render the template with the file name relative to the './templates'.
|
||||||
// file extension is OPTIONAL.
|
// file extension is OPTIONAL.
|
||||||
if err := ctx.View("hi.html"); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -51,7 +52,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := ctx.View("example.html", examplePage); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -80,7 +81,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := ctx.View("example.html", examplePage); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -97,7 +98,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := ctx.View("functions.html", functionsPage); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "github.com/kataras/iris/v12"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/kataras/iris/v12"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
e := iris.Django(nil, ".html") // You can still use a file system though.
|
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{
|
if err := ctx.View("program.html", iris.Map{
|
||||||
"Name": "Gerasimos",
|
"Name": "Gerasimos",
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
ctx.HTML("<h3>%s</h3>", err.Error())
|
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "github.com/kataras/iris/v12"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/kataras/iris/v12"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
e := iris.Handlebars(nil, ".html") // You can still use a file system though.
|
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{
|
if err := ctx.View("program.html", iris.Map{
|
||||||
"Name": "Gerasimos",
|
"Name": "Gerasimos",
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
ctx.HTML("<h3>%s</h3>", err.Error())
|
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
"github.com/kataras/iris/v12"
|
"github.com/kataras/iris/v12"
|
||||||
@@ -30,7 +31,7 @@ func index(ctx iris.Context) {
|
|||||||
if err := ctx.View("program.jet", iris.Map{
|
if err := ctx.View("program.jet", iris.Map{
|
||||||
"Name": "Gerasimos",
|
"Name": "Gerasimos",
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
ctx.HTML("<h3>%s</h3>", err.Error())
|
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,11 @@
|
|||||||
// template parsers navigate through the example's subdirectories.
|
// template parsers navigate through the example's subdirectories.
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "github.com/kataras/iris/v12"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/kataras/iris/v12"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// To not load any templates from files or embedded data,
|
// 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{
|
if err := ctx.View("program.html", iris.Map{
|
||||||
"Name": "Gerasimos",
|
"Name": "Gerasimos",
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
ctx.HTML("<h3>%s</h3>", err.Error())
|
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "github.com/kataras/iris/v12"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/kataras/iris/v12"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
app := iris.New()
|
app := iris.New()
|
||||||
@@ -15,7 +19,7 @@ func main() {
|
|||||||
if err := ctx.View("index", iris.Map{
|
if err := ctx.View("index", iris.Map{
|
||||||
"Title": "Title of The Page",
|
"Title": "Title of The Page",
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
ctx.HTML("<h3>%s</h3>", err.Error())
|
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -25,7 +29,7 @@ func main() {
|
|||||||
if err := ctx.View("index", iris.Map{ // file extension is optional.
|
if err := ctx.View("index", iris.Map{ // file extension is optional.
|
||||||
"Title": "Title of the main Page",
|
"Title": "Title of the main Page",
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
ctx.HTML("<h3>%s</h3>", err.Error())
|
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "github.com/kataras/iris/v12"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/kataras/iris/v12"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
app := iris.New()
|
app := iris.New()
|
||||||
@@ -20,7 +24,7 @@ func index(ctx iris.Context) {
|
|||||||
|
|
||||||
ctx.ViewLayout("main")
|
ctx.ViewLayout("main")
|
||||||
if err := ctx.View("index", data); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -35,7 +39,7 @@ func internalServerError(ctx iris.Context) {
|
|||||||
|
|
||||||
ctx.ViewLayout("error")
|
ctx.ViewLayout("error")
|
||||||
if err := ctx.View("500", data); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
package main
|
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
|
// $ go install github.com/go-bindata/go-bindata/v3/go-bindata@latest
|
||||||
//
|
//
|
||||||
@@ -29,7 +33,7 @@ func index(ctx iris.Context) {
|
|||||||
|
|
||||||
ctx.ViewLayout("main")
|
ctx.ViewLayout("main")
|
||||||
if err := ctx.View("index", data); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -44,7 +48,7 @@ func internalServerError(ctx iris.Context) {
|
|||||||
|
|
||||||
ctx.ViewLayout("error")
|
ctx.ViewLayout("error")
|
||||||
if err := ctx.View("500", data); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/kataras/iris/v12"
|
"github.com/kataras/iris/v12"
|
||||||
@@ -40,7 +41,7 @@ func hi(ctx iris.Context) {
|
|||||||
"name": "iris",
|
"name": "iris",
|
||||||
"serverStartTime": startTime,
|
"serverStartTime": startTime,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
ctx.HTML("<h3>%s</h3>", err.Error())
|
ctx.HTML(fmt.Sprintf("<h3>%s</h3>", err.Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "github.com/kataras/iris/v12"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/kataras/iris/v12"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
app := iris.New()
|
app := iris.New()
|
||||||
@@ -31,7 +35,7 @@ func main() {
|
|||||||
paramsAsArray := []string{"theParam1", "theParam2", "paramThirdAfterStatic"}
|
paramsAsArray := []string{"theParam1", "theParam2", "paramThirdAfterStatic"}
|
||||||
ctx.ViewData("ParamsAsArray", paramsAsArray)
|
ctx.ViewData("ParamsAsArray", paramsAsArray)
|
||||||
if err := ctx.View("page.html"); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/kataras/iris/v12"
|
"github.com/kataras/iris/v12"
|
||||||
"github.com/kataras/iris/v12/mvc"
|
"github.com/kataras/iris/v12/mvc"
|
||||||
)
|
)
|
||||||
@@ -29,7 +31,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := ctx.View("example.html", viewData); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/kataras/iris/v12"
|
"github.com/kataras/iris/v12"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -32,7 +34,7 @@ func hi(ctx iris.Context) {
|
|||||||
ctx.ViewData("Name", "iris") // {{.Name}} will render: iris
|
ctx.ViewData("Name", "iris") // {{.Name}} will render: iris
|
||||||
// ctx.ViewData("", myCcustomStruct{})
|
// ctx.ViewData("", myCcustomStruct{})
|
||||||
if err := ctx.View("hi.html"); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/kataras/iris/v12"
|
"github.com/kataras/iris/v12"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -19,7 +21,7 @@ func main() {
|
|||||||
ctx.CompressWriter(true)
|
ctx.CompressWriter(true)
|
||||||
ctx.ViewData("", mypage{"My Page title", "Hello world!"})
|
ctx.ViewData("", mypage{"My Page title", "Hello world!"})
|
||||||
if err := ctx.View("mypage.html"); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
// Note that: you can pass "layout" : "otherLayout.html" to bypass the config's Layout property
|
// Note that: you can pass "layout" : "otherLayout.html" to bypass the config's Layout property
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/kataras/iris/v12"
|
"github.com/kataras/iris/v12"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -18,7 +20,7 @@ func main() {
|
|||||||
app.Get("/", func(ctx iris.Context) {
|
app.Get("/", func(ctx iris.Context) {
|
||||||
if err := ctx.View("page1.html"); err != nil {
|
if err := ctx.View("page1.html"); err != nil {
|
||||||
ctx.StatusCode(iris.StatusInternalServerError)
|
ctx.StatusCode(iris.StatusInternalServerError)
|
||||||
ctx.Writef(err.Error())
|
ctx.WriteString(err.Error())
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -27,7 +29,7 @@ func main() {
|
|||||||
ctx.ViewLayout(iris.NoLayout)
|
ctx.ViewLayout(iris.NoLayout)
|
||||||
if err := ctx.View("page1.html"); err != nil {
|
if err := ctx.View("page1.html"); err != nil {
|
||||||
ctx.StatusCode(iris.StatusInternalServerError)
|
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.
|
{ // both of these will use the layouts/mylayout.html as their layout.
|
||||||
my.Get("/", func(ctx iris.Context) {
|
my.Get("/", func(ctx iris.Context) {
|
||||||
if err := ctx.View("page1.html"); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
my.Get("/other", func(ctx iris.Context) {
|
my.Get("/other", func(ctx iris.Context) {
|
||||||
if err := ctx.View("page1.html"); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/kataras/iris/v12"
|
"github.com/kataras/iris/v12"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -35,7 +37,7 @@ func main() {
|
|||||||
paramsAsArray := []string{"theParam1", "theParam2", "paramThirdAfterStatic"}
|
paramsAsArray := []string{"theParam1", "theParam2", "paramThirdAfterStatic"}
|
||||||
ctx.ViewData("ParamsAsArray", paramsAsArray)
|
ctx.ViewData("ParamsAsArray", paramsAsArray)
|
||||||
if err := ctx.View("page.html"); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/kataras/iris/v12"
|
"github.com/kataras/iris/v12"
|
||||||
"github.com/kataras/iris/v12/core/router"
|
"github.com/kataras/iris/v12/core/router"
|
||||||
)
|
)
|
||||||
@@ -52,7 +54,7 @@ func main() {
|
|||||||
paramsAsArray := []string{"username5", "theParam1", "theParam2", "paramThirdAfterStatic"}
|
paramsAsArray := []string{"username5", "theParam1", "theParam2", "paramThirdAfterStatic"}
|
||||||
ctx.ViewData("ParamsAsArray", paramsAsArray)
|
ctx.ViewData("ParamsAsArray", paramsAsArray)
|
||||||
if err := ctx.View("page.html"); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/kataras/iris/v12"
|
"github.com/kataras/iris/v12"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -13,7 +15,7 @@ func main() {
|
|||||||
app.Get("/home", func(ctx iris.Context) {
|
app.Get("/home", func(ctx iris.Context) {
|
||||||
ctx.ViewData("title", "Home page")
|
ctx.ViewData("title", "Home page")
|
||||||
if err := ctx.View("home.html"); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,14 +26,14 @@ func main() {
|
|||||||
|
|
||||||
app.Get("/about", func(ctx iris.Context) {
|
app.Get("/about", func(ctx iris.Context) {
|
||||||
if err := ctx.View("about.html"); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
app.Get("/user/index", func(ctx iris.Context) {
|
app.Get("/user/index", func(ctx iris.Context) {
|
||||||
if err := ctx.View("user/index.html"); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ func main() {
|
|||||||
|
|
||||||
ctx.ViewData("title", "Show TODO")
|
ctx.ViewData("title", "Show TODO")
|
||||||
if err := ctx.View("todos/show.jet", todo); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -136,7 +136,7 @@ func main() {
|
|||||||
// and ctx.View("todos/index.jet")
|
// and ctx.View("todos/index.jet")
|
||||||
// OR
|
// OR
|
||||||
if err := ctx.View("todos/index.jet", (&doneTODOs{}).New(todos)); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/kataras/iris/v12"
|
"github.com/kataras/iris/v12"
|
||||||
@@ -23,7 +24,7 @@ func main() {
|
|||||||
|
|
||||||
app.Get("/", func(ctx iris.Context) {
|
app.Get("/", func(ctx iris.Context) {
|
||||||
if err := ctx.View("index.jet"); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/kataras/iris/v12"
|
"github.com/kataras/iris/v12"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -34,7 +36,7 @@ func main() {
|
|||||||
paramsAsArray := []string{"theParam1", "theParam2", "paramThirdAfterStatic"}
|
paramsAsArray := []string{"theParam1", "theParam2", "paramThirdAfterStatic"}
|
||||||
ctx.ViewData("ParamsAsArray", paramsAsArray)
|
ctx.ViewData("ParamsAsArray", paramsAsArray)
|
||||||
if err := ctx.View("page.jet"); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ func main() {
|
|||||||
|
|
||||||
app.Get("/", func(ctx iris.Context) {
|
app.Get("/", func(ctx iris.Context) {
|
||||||
if err := ctx.View("index.jet"); err != nil {
|
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
|
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 shows an example of pug actions based on https://github.com/Joker/jade/tree/master/example/actions
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "github.com/kataras/iris/v12"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/kataras/iris/v12"
|
||||||
|
)
|
||||||
|
|
||||||
type Person struct {
|
type Person struct {
|
||||||
Name string
|
Name string
|
||||||
@@ -39,7 +43,7 @@ func index(ctx iris.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := ctx.View("index.pug", person); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
|
|
||||||
"github.com/kataras/iris/v12"
|
"github.com/kataras/iris/v12"
|
||||||
@@ -25,7 +26,7 @@ func main() {
|
|||||||
|
|
||||||
func index(ctx iris.Context) {
|
func index(ctx iris.Context) {
|
||||||
if err := ctx.View("index.pug"); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
package main
|
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
|
// $ go install github.com/go-bindata/go-bindata/v3/go-bindata@latest
|
||||||
//
|
//
|
||||||
@@ -23,7 +27,7 @@ func main() {
|
|||||||
|
|
||||||
func index(ctx iris.Context) {
|
func index(ctx iris.Context) {
|
||||||
if err := ctx.View("index.pug"); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -147,7 +148,7 @@ func serveHome(ctx iris.Context) {
|
|||||||
strconv.FormatInt(lastMod.UnixNano(), 16),
|
strconv.FormatInt(lastMod.UnixNano(), 16),
|
||||||
}
|
}
|
||||||
if err := ctx.View("home.html", v); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/kataras/iris/v12"
|
"github.com/kataras/iris/v12"
|
||||||
@@ -50,7 +51,7 @@ func main() {
|
|||||||
|
|
||||||
app.Get("/", func(ctx iris.Context) {
|
app.Get("/", func(ctx iris.Context) {
|
||||||
if err := ctx.View("client.html", clientPage{"Client Page", "localhost:8080"}); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ func main() {
|
|||||||
h := func(ctx iris.Context) {
|
h := func(ctx iris.Context) {
|
||||||
ctx.ViewData("", page{PageID: "index page"})
|
ctx.ViewData("", page{PageID: "index page"})
|
||||||
if err := ctx.View("index.html"); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -42,7 +42,7 @@ func main() {
|
|||||||
h2 := func(ctx iris.Context) {
|
h2 := func(ctx iris.Context) {
|
||||||
ctx.ViewData("", page{PageID: "other page"})
|
ctx.ViewData("", page{PageID: "other page"})
|
||||||
if err := ctx.View("other.html"); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-6
@@ -792,9 +792,9 @@ func (ctx *Context) StopWithStatus(statusCode int) {
|
|||||||
//
|
//
|
||||||
// If the status code is a failure one then
|
// If the status code is a failure one then
|
||||||
// it will also fire the specified error code handler.
|
// 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.StopWithStatus(statusCode)
|
||||||
ctx.WriteString(fmt.Sprintf(format, args...))
|
ctx.WriteString(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
// StopWithError stops the handlers chain and writes the "statusCode"
|
// 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.
|
// 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)
|
ctx.ContentType(ContentTextHeaderValue)
|
||||||
return ctx.Writef(format, args...)
|
return ctx.WriteString(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
// HTML writes out a string as text/html.
|
// 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)
|
ctx.ContentType(ContentHTMLHeaderValue)
|
||||||
return ctx.Writef(format, args...)
|
return ctx.WriteString(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ProtoMarshalOptions is a type alias for protojson.MarshalOptions.
|
// 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) {
|
// my.Get("/", func(ctx iris.Context) {
|
||||||
// if err := ctx.View("page1.html"); err != nil {
|
// 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
|
// return
|
||||||
// }
|
// }
|
||||||
// })
|
// })
|
||||||
|
|||||||
@@ -466,7 +466,7 @@ type Party interface {
|
|||||||
// my := app.Party("/my").Layout("layouts/mylayout.html")
|
// my := app.Party("/my").Layout("layouts/mylayout.html")
|
||||||
// my.Get("/", func(ctx iris.Context) {
|
// my.Get("/", func(ctx iris.Context) {
|
||||||
// if err := ctx.View("page1.html"); err != nil {
|
// 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
|
// return
|
||||||
// }
|
// }
|
||||||
// })
|
// })
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package router_test
|
package router_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -200,7 +201,7 @@ func TestNewSubdomainPartyRedirectHandler(t *testing.T) {
|
|||||||
func TestHandleServer(t *testing.T) {
|
func TestHandleServer(t *testing.T) {
|
||||||
otherApp := iris.New()
|
otherApp := iris.New()
|
||||||
otherApp.Get("/test/me/{first:string}", func(ctx iris.Context) {
|
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()
|
otherApp.Build()
|
||||||
|
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ var h2 = func(ctx *context.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func h3(ctx *context.Context) {
|
func h3(ctx *context.Context) {
|
||||||
ctx.Writef(staticPathPrefixBody + ctx.Path())
|
ctx.WriteString(staticPathPrefixBody + ctx.Path())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRouterWildcardDifferentPrefixPath(t *testing.T) {
|
func TestRouterWildcardDifferentPrefixPath(t *testing.T) {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package hero_test
|
package hero_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -111,9 +112,9 @@ func TestDependentDependency(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{ // 3
|
{ // 3
|
||||||
Dependency: func(msg testMessage) error {
|
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.
|
// Test depend on more than one previous registered dependencies and require a before-previous one.
|
||||||
{ // 4
|
{ // 4
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package parser
|
package parser
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -101,7 +102,7 @@ const (
|
|||||||
|
|
||||||
func (p ParamParser) Error() error {
|
func (p ParamParser) Error() error {
|
||||||
if len(p.errors) > 0 {
|
if len(p.errors) > 0 {
|
||||||
return fmt.Errorf(strings.Join(p.errors, "\n"))
|
return errors.New(strings.Join(p.errors, "\n"))
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ func DefaultErrorHandler(ctx *context.Context, err error) {
|
|||||||
unauthorize(ctx, e.AuthenticateHeader, e.AuthenticateHeaderValue, e.Code)
|
unauthorize(ctx, e.AuthenticateHeader, e.AuthenticateHeaderValue, e.Code)
|
||||||
default:
|
default:
|
||||||
// This will never happen.
|
// 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/core/router"
|
||||||
"github.com/kataras/iris/v12/macro"
|
"github.com/kataras/iris/v12/macro"
|
||||||
|
|
||||||
|
"golang.org/x/text/cases"
|
||||||
|
"golang.org/x/text/language"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -137,8 +140,8 @@ func parseMethod(macros *macro.Macros, fn reflect.Method, skipper func(string) b
|
|||||||
}
|
}
|
||||||
|
|
||||||
func methodTitle(httpMethod string) string {
|
func methodTitle(httpMethod string) string {
|
||||||
httpMethodFuncName := strings.Title(strings.ToLower(httpMethod))
|
caser := cases.Title(language.English)
|
||||||
return httpMethodFuncName
|
return caser.String(strings.ToLower(httpMethod))
|
||||||
}
|
}
|
||||||
|
|
||||||
var errSkip = errors.New("skip")
|
var errSkip = errors.New("skip")
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ type testController struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var writeMethod = func(ctx *context.Context) {
|
var writeMethod = func(ctx *context.Context) {
|
||||||
ctx.Writef(ctx.Method())
|
ctx.WriteString(ctx.Method())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *testController) Get() {
|
func (c *testController) Get() {
|
||||||
@@ -108,15 +108,15 @@ func (c *testControllerBeginAndEndRequestFunc) BeginRequest(ctx *context.Context
|
|||||||
|
|
||||||
// called after every method (Get() or Post()).
|
// called after every method (Get() or Post()).
|
||||||
func (c *testControllerBeginAndEndRequestFunc) EndRequest(ctx *context.Context) {
|
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() {
|
func (c *testControllerBeginAndEndRequestFunc) Get() {
|
||||||
c.Ctx.Writef(c.Username)
|
c.Ctx.WriteString(c.Username)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *testControllerBeginAndEndRequestFunc) Post() {
|
func (c *testControllerBeginAndEndRequestFunc) Post() {
|
||||||
c.Ctx.Writef(c.Username)
|
c.Ctx.WriteString(c.Username)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestControllerBeginAndEndRequestFunc(t *testing.T) {
|
func TestControllerBeginAndEndRequestFunc(t *testing.T) {
|
||||||
@@ -230,7 +230,7 @@ func writeModels(ctx *context.Context, names ...string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Writef(model.Username)
|
ctx.WriteString(model.Username)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -269,7 +269,7 @@ type testControllerBindStruct struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *testControllerBindStruct) Get() {
|
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
|
// 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() {
|
func (t *testControllerBindDeep) Get() {
|
||||||
// t.testControllerBindStruct.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 {
|
func (t *testControllerBindDeep) Post(v testCustomStruct) string {
|
||||||
@@ -338,9 +338,9 @@ func (c *testCtrl0) Get() string {
|
|||||||
|
|
||||||
func (c *testCtrl0) EndRequest(ctx *context.Context) {
|
func (c *testCtrl0) EndRequest(ctx *context.Context) {
|
||||||
if c.TitlePointer == nil {
|
if c.TitlePointer == nil {
|
||||||
ctx.Writef("\nTitlePointer is nil!\n")
|
ctx.WriteString("\nTitlePointer is nil!\n")
|
||||||
} else {
|
} else {
|
||||||
ctx.Writef(c.TitlePointer.title)
|
ctx.WriteString(c.TitlePointer.title)
|
||||||
}
|
}
|
||||||
|
|
||||||
// should be the same as `.testCtrl000.testCtrl0000.EndRequest(ctx)`
|
// should be the same as `.testCtrl000.testCtrl0000.EndRequest(ctx)`
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ func testSessions(t *testing.T, app *iris.Application) {
|
|||||||
ctx.Next()
|
ctx.Next()
|
||||||
}, func(ctx *context.Context) {
|
}, func(ctx *context.Context) {
|
||||||
s := sessions.Get(ctx)
|
s := sessions.Get(ctx)
|
||||||
_, err := ctx.Writef(s.GetString("key"))
|
_, err := ctx.WriteString(s.GetString("key"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -44,7 +44,7 @@ func main() {
|
|||||||
ctx.ViewData("message", "Hello world!")
|
ctx.ViewData("message", "Hello world!")
|
||||||
// Render template file: ./views/hello.html
|
// Render template file: ./views/hello.html
|
||||||
if err := ctx.View("hello.html"); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -109,7 +109,7 @@ func main() {
|
|||||||
func hi(ctx iris.Context) {
|
func hi(ctx iris.Context) {
|
||||||
// render the template file "./templates/hi.html"
|
// render the template file "./templates/hi.html"
|
||||||
if err := ctx.View("hi.html"); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -156,7 +156,7 @@ func hi(ctx iris.Context) {
|
|||||||
// {{.Page.Title}} and {{Page.Name}}
|
// {{.Page.Title}} and {{Page.Name}}
|
||||||
ctx.ViewData("Page", page{Title: "Hi Page", Name: "iris"})
|
ctx.ViewData("Page", page{Title: "Hi Page", Name: "iris"})
|
||||||
if err := ctx.View("hi.html"); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-5
@@ -271,13 +271,13 @@ func (e ErrorCodeName) MapErrors(targets ...error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Message sends an error with a simple message to the client.
|
// Message sends an error with a simple message to the client.
|
||||||
func (e ErrorCodeName) Message(ctx *context.Context, format string, args ...interface{}) {
|
func (e ErrorCodeName) Message(ctx *context.Context, msg string) {
|
||||||
fail(ctx, e, sprintf(format, args...), "", nil, nil)
|
fail(ctx, e, msg, "", nil, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Details sends an error with a message and details to the client.
|
// Details sends an error with a message and details to the client.
|
||||||
func (e ErrorCodeName) Details(ctx *context.Context, msg, details string, detailsArgs ...interface{}) {
|
func (e ErrorCodeName) Details(ctx *context.Context, msg, details string) {
|
||||||
fail(ctx, e, msg, sprintf(details, detailsArgs...), nil, nil)
|
fail(ctx, e, msg, msg, nil, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Data sends an error with a message and json data to the client.
|
// 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
|
var syntaxErr *json.SyntaxError
|
||||||
if errors.As(err, &syntaxErr) {
|
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
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -220,7 +220,7 @@ func Validation[T any](validators ...ContextRequestFunc[T]) context.Handler {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
validator := joinContextRequestFuncs[T](validators)
|
validator := joinContextRequestFuncs(validators)
|
||||||
|
|
||||||
return func(ctx *context.Context) {
|
return func(ctx *context.Context) {
|
||||||
ctx.Values().Set(contextRequestHandlerFuncKey, validator)
|
ctx.Values().Set(contextRequestHandlerFuncKey, validator)
|
||||||
@@ -322,7 +322,7 @@ func Intercept[T, R any](responseHandlers ...ContextResponseFunc[T, R]) context.
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
responseHandler := joinContextResponseFuncs[T, R](responseHandlers)
|
responseHandler := joinContextResponseFuncs(responseHandlers)
|
||||||
|
|
||||||
return func(ctx *context.Context) {
|
return func(ctx *context.Context) {
|
||||||
ctx.Values().Set(contextResponseHandlerFuncKey, responseHandler)
|
ctx.Values().Set(contextResponseHandlerFuncKey, responseHandler)
|
||||||
|
|||||||
Reference in New Issue
Block a user