Hi

package main

import "github.com/kataras/iris"

func main() {
    iris.Get("/hi", func(ctx *iris.Context) {
        ctx.Writef("Hi %s", "iris")
    })
    iris.Listen(":8080")
}

The same:

package main

import "github.com/kataras/iris"

func main() {
    api := iris.New()
    api.Get("/hi", hi)
    api.Listen(":8080")
}

func hi(ctx *iris.Context){
   ctx.Writef("Hi %s", "iris")
}

Rich Hi with html\/template:

<!-- ./templates/hi.html -->
<html><head> <title> Hi Iris</title> </head>
  <body>
    <h1> Hi {{.Name}} </h1>
  </body>
</html>
// ./main.go
import "github.com/kataras/iris"

func main() {
    iris.Get("/hi", hi)
    iris.Listen(":8080")
}

func hi(ctx *iris.Context){
   ctx.Render("hi.html", struct { Name string }{ Name: "iris" })
}

Rich Hi with Django-syntax:

<!-- ./mytemplates/hi.html -->
<html><head> <title> Hi Iris </title> </head>
  <body>
    <h1> Hi {{ Name }}
  </body>
</html>
// ./main.go
import (
    "github.com/kataras/iris"
    "github.com/kataras/go-template/django"
)

func main() {
    iris.UseTemplate(django.New()).Directory("./mytemplates", ".html")
    iris.Get("/hi", hi)
    iris.Listen(":8080")
}

func hi(ctx *iris.Context){
   ctx.Render("hi.html", map[string]interface{}{"Name": "iris"}, iris.RenderOptions{"gzip":true})
}

More about render and template engines here.

results matching ""

    No results matching ""