Iris-go的2个疑惑:type与方法

XinhongWu · · 773 次点击 · 开始浏览    置顶
这是一个创建于 的主题,其中的信息可能已经有所发展或是发生改变。

初次接触Golang,在阅读Iris源码的时候,有2处看不懂,特来请教一下: 1)在文件go19.go中,看到type有如下的用法: type ( Context = context.Context UnmarshalerFunc = context.UnmarshalerFunc Map = context.Map ...... ) 这个是Type的什么用法呢?直接在VSCode测试,发现会有编译错误,是否这样写是有前提的? 2)在example的overview目录中,有如下的一段代码: func main() { app := iris.New() // app.Logger().SetLevel("disable") to disable the logger // Define templates using the std html/template engine. // Parse and load all files inside "./views" folder with ".html" file extension. // Reload the templates on each request (development mode). app.RegisterView(iris.HTML("./views", ".html").Reload(true)) // Register custom handler for specific http errors. app.OnErrorCode(iris.StatusInternalServerError, func(ctx iris.Context) { // .Values are used to communicate between handlers, middleware. errMessage := ctx.Values().GetString("error") if errMessage != "" { ctx.Writef("Internal server error: %s", errMessage) return } ctx.Writef("(Unexpected) internal server error") }) app.Use(func(ctx iris.Context) { ctx.Application().Logger().Infof("Begin request for path: %s", ctx.Path()) ctx.Next() }) ..................} 疑惑之处:OnErrorCode 这个函数在Application中并不能找到,而是在APIBuilder中发现有,但是这2个不是一个struct,能这样调用吗?希望不吝赐教

有疑问加站长微信联系(非本文作者)

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

773 次点击  
加入收藏 微博
4 回复  |  直到 2018-12-28 13:54:25
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传