It's funny because the https://github.com/kataras/iris and the https://iris-go.com and https://docs.iris-go.com have many examples of those things, you spend your time asking that, you probably checked a third-party fork of Iris and not the Iris itself where did you find that code snippet?
The correct way:
package main
import "github.com/kataras/iris"
func main() {
app := iris.New()
app.Get("/hi", func(ctx iris.Context) { // go > 1.9
ctx.Writef("Hi %s", "iris")
})
app.Run(iris.Addr(":8080"))
}
Here's another example, a simple server which renders a template file with message to the client:
// file: main.go
package main
import "github.com/kataras/iris"
func main() {
app := iris.New()
// Load all templates from the "./views" folder
// where extension is ".html" and parse them
// using the standard `html/template` package.
app.RegisterView(iris.HTML("./views", ".html"))
// Method: GET
// Resource: http://localhost:8080
app.Get("/", func(ctx iris.Context) {
// Bind: {{.message}} with "Hello world!"
ctx.ViewData("message", "Hello world!")
// Render template file: ./views/hello.html
ctx.View("hello.html")
})
// Method: GET
// Resource: http://localhost:8080/user/42
app.Get("/user/{id:long}", func(ctx iris.Context) {
userID, _ := ctx.Params().GetInt64("id")
ctx.Writef("User ID: %d", userID)
})
// Start the server using a network address.
app.Run(iris.Addr(":8080"))
}
<!-- file: ./views/hello.html -->
<html>
<head>
<title>Hello Page</title>
</head>
<body>
<h1>{{.message}}</h1>
</body>
</html>
$ go run main.go
> Now listening on: http://localhost:8080
> Application started. Press CTRL+C to shut down.
If you ever need any help with Iris you can always contact with the support team via the live chat https://chat.iris-go.com. Have a nice day!