douwen1929 2018-11-08 21:08
浏览 37
已采纳

无法导入位于同一目录中的软件包

I want to import in the current file or package other file located in the same project in a directory. I'm doing this:

import (

// "./dir1"
  "/Users/my_name/my_project/dir1"

)

None of them works

  1) Cloning into '/Users/my_name/go/src/github.com/github_username/github_project'...
  fatal: could not read Username for 'https://github.com': terminal prompts disabled


  2) package /Users/my_name/my_project/dir1: unrecognized import path "/Users/my_name/my_project/dir1" (import path does not begin with hostname)

How to import a directory located in the current project?

  • 写回答

3条回答 默认 最新

  • doudi5892 2018-11-09 00:51
    关注

    Rename dir1 to to the same name as the package inside that directory, then you can import it with:

    import "./package1"
    

    However doing this is not recommended, use GOPATH instead. If you really don't want to use GOPATH, you may want to use Modules in Go 1.11 (but it is still experimental).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥20 使用Photon PUN2解决游戏得分同步的问题
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM