dra8603 2015-12-16 16:03
浏览 92
已采纳

Go中正确的编码方式是什么?

Recently I found that Revel is a really good MVC web framework, and I want to try it out. The problem is that I'm new to Go and everything seems a little different.

When using PHP, I just put files into /var/www/ folder, or use some IDE, then I can open browser and test them live. It's even easier with RoR or Node.js, I just go to local project folder (doesn't matter where), run one command in terminal and already can see the result on localhost:3000.

This way, I have the following structure on my local machine:

home
└── mark
    └── code
        ├── php
        │   └── my_php_app
        └── ruby
            └── my_ruby_app

They all are synced via git. Then, when I want to deploy on my remote machine, I just pull them into /var/www/ and set up Apache2/Nginx

But how do I do this with Go apps? I installed Go both on my Linux machine at home, and on my VPS. When I open ~/code/go/mygoapp and try to run it with revel run, it says that it's not found in GOPATH. So, I assume, I need to keep all my Go projects separately from my other projects, in GOPATH, which could be /usr/local/go/src/ or ~/gocode/src/.

Questions are:

  1. What should I do, if I want to keep all my Go/Revel projects in go folder along with php and ruby on local machine like that:

    home
    └── mark
        └── code
            ├── go
            │   └── my_revel_app
            ├── php
            │   └── my_php_app
            └── ruby
                └── my_ruby_app
    
  2. And how do I actually deploy them on my remote server the correct way?

  3. If I still need to use GOPATH for that, how do I name the packages? Is it GOPATH/src/mygoapp, GOPATH/src/mark/mygoapp or GOPATH/src/bitbucket.org/mark/mygoapp (while this repo is private)?

I know, this could be a noob question, but I don't see a logic here. Even with simple Go programs, I don't need to put them to GOPATH in order to run.

  • 写回答

3条回答 默认 最新

  • dongshilve4392 2015-12-16 16:12
    关注

    You add directories (workspaces) to GOPATH which contain go source, and conform to the structure src, pkg, bin. You can have as many go workspaces as you want in your GOPATH. Define the variable accordingly on your systems. The GOPATH on your server will most likely be different than the one your local machine.

    You can use git to share your projects. Create an account on github or bitbucket, and synchronize.

    Your GOPATH points to go workspaces. The first one is used to store the go get packages.

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

报告相同问题?

悬赏问题

  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序