dongtu0088 2017-04-20 21:18
浏览 37
已采纳

导入软件包的正确项目结构

As the title here is my current structure for Go app that serves static http page and also sends data through websocket.

In the structure below I have 2 packages constants and main and am unable to use constants from main package.

Server-Client Game
    assets
        css
            index.css
        js
            app.js
        templates
            index.html
    constants
        server.go
        game.go
    main
        main.go
        hub.go
        player.go

Should I be using Go workspace? or can I get it working as is?

My project currently is not in the GoPath src which I was previously calling 'workspace'.

  • 写回答

2条回答 默认 最新

  • duanjiaolia97750 2017-04-20 21:39
    关注

    you should have a gopath which should contain at least src and bin. your project source code will go into the src folder and your published binaries will go into your bin folder.

    for instance, if your go path points to c:/go-apps then your project may look like this . . .

    c:/go-apps/src/Server-Client Game/ ... 
    

    if you issue go install, your binaries will be in c:/go-apps/bin. since go also supports git repositories, you can import them directly into your project like this (assuming it is public)

    import "github.com/gorilla/mux"
    

    a statement like this will import the popular mux package from github. you can expect to find this in your gopath to be

    c:/go-apps/src/github.com/gorilla/mux
    

    also you may have multiple gopaths. when you compile an application, it will be looking in your gopath(s) for the package. if the package is not available it will automatically download them.

    alternatively to go install, you can use go build to build the binaries in the current folder. to simply download all the dependencies without compiling use go get.

    as for the folder structure, yes that should be fine, but i usually put my main in the root directory since package main and func() main is the entry point and only one package is allowed per directory in go.

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

报告相同问题?

悬赏问题

  • ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并—
  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址