【问题标题】:iris (Go web framework) iris.PongoEngine error from iris official bookiris (Go web framework) iris.PongoEngine error from iris 官书
【发布时间】:2016-07-18 20:53:41
【问题描述】:

我开始使用 Golang 的 Web 框架 (Iris)。我正在使用来自 gitbooks 的官方 iris 书。 我正在研究书中的last example in this page。 以下是上一个示例中使用的代码

./templates/hi.html

<!-- ./templates/hi.html -->
<html><head> <title> Hi Iris [THE TITLE] </title> </head>
  <body>
    <h1> Hi {{ Name }}
  </body>
</html>

./main.go

// ./main.go
import (
    "github.com/kataras/iris"
)

func main() {
    iris.Config.Render.Template.Engine = iris.PongoEngine
    iris.Get("/hi", hi)
    iris.Listen(":8080")
}

func hi(ctx *iris.Context){
   ctx.Render("hi.html", map[string]interface{}{"Name": "iris"})
}

当我运行 main.go 时,出现以下错误。

# command-line-arguments
./main.go:8: iris.Config.Render undefined (type *config.Iris has no field or method Render)
./main.go:8: undefined: iris.PongoEngine

我正确执行了所有步骤,还下载了所有依赖项。 Learn How To Code: Google's Go (golang) Programming Language - UdemyGolang Workshop by Caleb Doxcy 我已经用过了,所以我知道了基础知识,比如如何安装依赖项,以及如何导入它们等。但是书中显示的示例不起作用。

【问题讨论】:

  • master中的API好像改了。 README 建议通过 gopkg.in 获取包以获取 V3 分支。
  • @JimB 你的意思是我应该重新安装 iris(从 gopkg.in 中拉出来)?
  • 我投票决定将此问题作为离题结束,因为这是场外项目文档的问题,与编程无关。
  • 是的,看起来将所有导入路径更改为 gopkg.in/kataras/iris.v3 将解决此问题(或者您可以在本地签出 V3 分支,并保留导入路径)
  • @JimB 请不要关闭它。

标签: ubuntu go web go-iris


【解决方案1】:
import "github.com/kataras/iris/v12"

func main() {

    app := iris.New()
    app.RegisterView(iris.Django("./templates", ".html")) // <-----

    // RESOURCE: http://127.0.0.1:8080/hi
    // METHOD: "GET"
    app.Get("/hi", hi)

    app.Listen(":8080")
}

func hi(ctx iris.Context){
   ctx.ViewData("Name", "iris")
   ctx.View("hi.html")
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-04-29
    • 1970-01-01
    • 2022-12-02
    • 2021-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-02
    相关资源
    最近更新 更多