1 Star 0 Fork 0

yunduansing / iristest

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
Application.go 835 Bytes
一键复制 编辑 原始数据 按行查看 历史
xiangjun.lu 提交于 2021-01-27 10:50 . m
package application
import (
"gitee.com/yunduansing/gocommon/consul"
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/context"
)
func Init() (app *iris.Application) {
app=iris.Default()
app.Use(Recover())
RegisterService()
return
}
func RegisterService() {
err:=consul.Register("localhost:8500","localhost",8881,"iris-web")
if err!=nil{
panic(err)
}
}
func Recover() context.Handler {
return func(c iris.Context) {
defer func() {
if r:=recover();r!=nil{
c.JSON(iris.Map{
"success": false,
"msg": errorToString(r),
"data": nil,
})
//终止当前接口
c.StopExecution()
}
}()
c.Next()
}
}
// recover错误,转string
func errorToString(r interface{}) string {
switch v := r.(type) {
case error:
return v.Error()
default:
return r.(string)
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/yunduansing/iristest.git
git@gitee.com:yunduansing/iristest.git
yunduansing
iristest
iristest
v0.0.2

搜索帮助

344bd9b3 5694891 D2dac590 5694891