mirror of
https://github.com/kataras/iris.git
synced 2025-01-24 03:01:03 +01:00
f487cd0029
Former-commit-id: 98895c34115ec2076b431332f0ffe9645adf7590
48 lines
1.0 KiB
Go
48 lines
1.0 KiB
Go
package main
|
|
|
|
import (
|
|
"gopkg.in/kataras/iris.v6"
|
|
"gopkg.in/kataras/iris.v6/adaptors/httprouter"
|
|
"gopkg.in/kataras/iris.v6/adaptors/view"
|
|
)
|
|
|
|
// ContactDetails the information from user
|
|
type ContactDetails struct {
|
|
Email string `form:"email"`
|
|
Subject string `form:"subject"`
|
|
Message string `form:"message"`
|
|
}
|
|
|
|
func main() {
|
|
app := iris.New()
|
|
app.Adapt(httprouter.New())
|
|
|
|
// Parse all files inside `./mytemplates` directory ending with `.html`
|
|
app.Adapt(view.HTML("./mytemplates", ".html"))
|
|
|
|
app.Get("/", func(ctx *iris.Context) {
|
|
ctx.Render("forms.html", nil)
|
|
})
|
|
|
|
// Equivalent with app.HandleFunc("POST", ...)
|
|
app.Post("/", func(ctx *iris.Context) {
|
|
|
|
// details := ContactDetails{
|
|
// Email: ctx.FormValue("email"),
|
|
// Subject: ctx.FormValue("subject"),
|
|
// Message: ctx.FormValue("message"),
|
|
// }
|
|
|
|
// or simply:
|
|
var details ContactDetails
|
|
ctx.ReadForm(&details)
|
|
|
|
// do something with details
|
|
_ = details
|
|
|
|
ctx.Render("forms.html", struct{ Success bool }{true})
|
|
})
|
|
|
|
app.Listen(":8080")
|
|
}
|