zoukankan      html  css  js  c++  java
  • golang goland 模块设置,提示找不到目录

    working directory is not part of a module

    代码参考:https://www.studyiris.com/doc/irisDoc/Installation.html

        package main
        import "github.com/kataras/iris"
        func main() {
            app := iris.New()
            app.Get("/", func(ctx iris.Context){})
            app.Run(iris.Addr(":8080"))
        }
    

    报错如下:

    main.go:2:8: cannot find module providing package github.com/kataras/iris: working directory is not part of a module
    

    包的依赖我已经下载好了,存放到$GOPATH/pkg/mod下(注意有github.com就放到github.com目录下)。

    一直无非解决,直到这篇文字:https://www.jianshu.com/p/c666ebdb462b

    一般网上的资料都是建议在工程的根目录下执行go mod init projectName命令。在执行go mod化之后,所有的引用都不再是以GOPATH为相对路径的引用了,而是变成了以go.mod中初始化的项目名为起始的引用。

    $ go mod init main
    go: creating new go.mod: module main
    $ ls
    go.mod main.go
    $ go run main.go 
    go: finding module for package github.com/kataras/iris/v12
    go: found github.com/kataras/iris/v12 in github.com/kataras/iris/v12 v12.1.8
    go: finding module for package github.com/shurcooL/sanitized_anchor_name
    go: found github.com/shurcooL/sanitized_anchor_name in github.com/shurcooL/sanitized_anchor_name v1.0.0
    Now listening on: http://localhost:8080
    Application started. Press CMD+C to shut down.
    
     
     


    作者:日落_3d9f
    链接:https://www.jianshu.com/p/fb9a947ac8f3
    来源:简书
    著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
  • 相关阅读:
    drf3
    字典的操作方法
    列表的操作方法
    字符串的操作方法
    while循环和基本运算符
    初识数据类型
    USDT相关
    带团队
    CentOS7更改时区及同步网络时间
    mac胡刷新dns
  • 原文地址:https://www.cnblogs.com/xiami2046/p/13530366.html
Copyright © 2011-2022 走看看