douwei1930 2019-05-07 06:51
浏览 129

Golang:使用新的目录结构构建并运行

Brushing up on my golang, I see that there is a new recommended directory structure for go projects: We should be emitting the "src" directory from our project. Here is an example of such a project: https://github.com/golang-standards/project-layout , and I have also seen this mentioned in several recent articles.

Until now, I have created a package under /myproject/src/mypackage. Then, to run my project I would add /myproject to $GOPATH.

My question: If I use the new directory structure, how would I go about building and running my project? I could "hack" it by creating a symlink into a "src" directory... But that seems rather "dirty" (If I was going to do that, I could've just used "src" to begin with) .

I would appreciate if someone could point out the build and run commands for a project arranged in the structure mentioned above.

EDIT based on comments: This question is not about whether I want to use "src" or not. I definitely do want to embrace this new project structure. It's just that I cannot find instructions on how to build and run a project with such a directory structure. For example: How would I reference the files in the pkg directory if it's not in my "$GOPATH/myproject/src"?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
    • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
    • ¥15 划分vlan后,链路不通了?
    • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
    • ¥15 个人网站被恶意大量访问,怎么办
    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 Centos / PETGEM
    • ¥15 划分vlan后不通了
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)