2020-09-05 07:34:09 +02:00
|
|
|
// Package main shows an example of pug actions based on https://github.com/Joker/jade/tree/master/example/actions
|
2018-05-26 21:49:48 +02:00
|
|
|
package main
|
|
|
|
|
2019-10-25 00:27:02 +02:00
|
|
|
import "github.com/kataras/iris/v12"
|
2018-05-26 21:49:48 +02:00
|
|
|
|
2020-09-05 07:34:09 +02:00
|
|
|
type Person struct {
|
|
|
|
Name string
|
|
|
|
Age int
|
|
|
|
Emails []string
|
|
|
|
Jobs []*Job
|
|
|
|
}
|
|
|
|
|
|
|
|
type Job struct {
|
|
|
|
Employer string
|
|
|
|
Role string
|
|
|
|
}
|
|
|
|
|
2018-05-26 21:49:48 +02:00
|
|
|
func main() {
|
|
|
|
app := iris.New()
|
|
|
|
|
|
|
|
tmpl := iris.Pug("./templates", ".pug")
|
|
|
|
app.RegisterView(tmpl)
|
|
|
|
|
|
|
|
app.Get("/", index)
|
|
|
|
|
|
|
|
// http://localhost:8080
|
2020-03-05 21:41:27 +01:00
|
|
|
app.Listen(":8080")
|
2018-05-26 21:49:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func index(ctx iris.Context) {
|
2020-09-05 07:34:09 +02:00
|
|
|
job1 := Job{Employer: "Monash B", Role: "Honorary"}
|
|
|
|
job2 := Job{Employer: "Box Hill", Role: "Head of HE"}
|
|
|
|
|
|
|
|
person := Person{
|
|
|
|
Name: "jan",
|
|
|
|
Age: 50,
|
|
|
|
Emails: []string{"jan@newmarch.name", "jan.newmarch@gmail.com"},
|
|
|
|
Jobs: []*Job{&job1, &job2},
|
|
|
|
}
|
|
|
|
|
2022-12-13 00:37:15 +01:00
|
|
|
if err := ctx.View("index.pug", person); err != nil {
|
|
|
|
ctx.HTML("<h3>%s</h3>", err.Error())
|
|
|
|
return
|
|
|
|
}
|
2018-05-26 21:49:48 +02:00
|
|
|
}
|