main.go
package main
import (
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/context"
)
func main() {
app := iris.New()
//字符串形式
app.Get("/getstring", func(context context.Context){
context.WriteString("Hello Test")
app.Logger().Info("getstring 测试")
})
//html格式
app.Get("/gethtml", func(context context.Context){
context.Html("<h1>Hello Test</h1>")
app.Logger().Info("gethtml 测试")
})
//带参数
app.Get("/userinfo", func(context context.Context){
userName := context.URLParam("username")
app.Logger().Info("用户名:" + userName)
pwd := context.URLParam("pwd")
app.Logger().Info("密码:" + pwd)
context.Html("<h1>" + "用户名:" + userName + "</h1>")
context.Html("<h1>" + "密码:" + pwd + "</h1>")
})
}
测试:
127.0.0.1:8080/getstring
127.0.0.1:8080/gethtml
127.0.0.1:8080/userinfo?username=lisi&pwd=123abc
原文:https://www.cnblogs.com/udont/p/13603724.html