1 Star 0 Fork 0

hh / iris

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
hello.go 1.27 KB
一键复制 编辑 原始数据 按行查看 历史
// file: web/routes/hello.go
package routes
import (
"errors"
"github.com/kataras/iris/hero"
)
var helloView = hero.View{
Name: "hello/index.html",
Data: map[string]interface{}{
"Title": "Hello Page",
"MyMessage": "Welcome to my awesome website",
},
}
// Hello will return a predefined view with bind data.
//
// `hero.Result` is just an interface with a `Dispatch` function.
// `hero.Response` and `hero.View` are the built'n result type dispatchers
// you can even create custom response dispatchers by
// implementing the `github.com/kataras/iris/hero#Result` interface.
func Hello() hero.Result {
return helloView
}
// you can define a standard error in order to re-use anywhere in your app.
var errBadName = errors.New("bad name")
// you can just return it as error or even better
// wrap this error with an hero.Response to make it an hero.Result compatible type.
var badName = hero.Response{Err: errBadName, Code: 400}
// HelloName returns a "Hello {name}" response.
// Demos:
// curl -i http://localhost:8080/hello/iris
// curl -i http://localhost:8080/hello/anything
func HelloName(name string) hero.Result {
if name != "iris" {
return badName
}
// return hero.Response{Text: "Hello " + name} OR:
return hero.View{
Name: "hello/name.html",
Data: name,
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/w1229748769/iris.git
git@gitee.com:w1229748769/iris.git
w1229748769
iris
iris
v10.3.0

搜索帮助

344bd9b3 5694891 D2dac590 5694891