dongmian8108 2017-03-20 12:33
浏览 46

虹膜错误-未解决的“获取”

This is my code

`package main 
 import "github.com/kataras/iris"
 func main()    {
     iris.Get("/hi",    func(ctx    *iris.Context)  {
         ctx.Writef("Hi %s",    "iris")
     })
     iris.Listen(":8080")
 }`

I have "go get -u github.com/kataras/iris/iris" this is what i get, and i've been surving and still cannot solve this.

./IRIS.go:6: undefined: iris.Get
./IRIS.go:9: undefined: iris.Listen

This is my first time trying this framework, I followed from page https://docs.iris-go.com/ I though it would easy, but its really not, i only can do install iris, and this is my first worse hello world

I'm using Intellij Idea as my IDE

Please Help Me. Thanks

  • 写回答

2条回答 默认 最新

  • douzhan4522 2017-09-10 10:23
    关注

    It's funny because the https://github.com/kataras/iris and the https://iris-go.com and https://docs.iris-go.com have many examples of those things, you spend your time asking that, you probably checked a third-party fork of Iris and not the Iris itself where did you find that code snippet?

    The correct way:

    package main 
    import "github.com/kataras/iris"
    func main()    {
        app := iris.New()
        app.Get("/hi", func(ctx iris.Context)  { // go > 1.9
            ctx.Writef("Hi %s", "iris")
        })
        app.Run(iris.Addr(":8080"))
    }
    

    Here's another example, a simple server which renders a template file with message to the client:

    // file: main.go
    package main
    import "github.com/kataras/iris"
    
    func main() {
        app := iris.New()
        // Load all templates from the "./views" folder
        // where extension is ".html" and parse them
        // using the standard `html/template` package.
        app.RegisterView(iris.HTML("./views", ".html"))
    
        // Method:    GET
        // Resource:  http://localhost:8080
        app.Get("/", func(ctx iris.Context) {
            // Bind: {{.message}} with "Hello world!"
            ctx.ViewData("message", "Hello world!")
            // Render template file: ./views/hello.html
            ctx.View("hello.html")
        })
    
        // Method:    GET
        // Resource:  http://localhost:8080/user/42
        app.Get("/user/{id:long}", func(ctx iris.Context) {
            userID, _ := ctx.Params().GetInt64("id")
            ctx.Writef("User ID: %d", userID)
        })
    
        // Start the server using a network address.
        app.Run(iris.Addr(":8080"))
    }
    

    <!-- file: ./views/hello.html -->
    <html>
    <head>
        <title>Hello Page</title>
    </head>
    <body>
        <h1>{{.message}}</h1>
    </body>
    </html>
    

    $ go run main.go
    > Now listening on: http://localhost:8080
    > Application started. Press CTRL+C to shut down.
    

    If you ever need any help with Iris you can always contact with the support team via the live chat https://chat.iris-go.com. Have a nice day!

    评论

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题