英文:
How to run a Go project on Go server?
问题
我对GoLang没有经验。
我有一个Go项目,我想在我的本地服务器上运行它,我的服务器是Ubuntu 14.04。我已经安装了Go服务器和Go代理,并且它们正在运行。
根据命令行的输出,/var/go/
是我可以用来放置我的Go项目的文件夹。根据我对Apache服务器的了解,我们可以从本地主机访问www
文件夹。所以,我期望Go服务器也有类似的文件夹(但似乎我错了)。
我的项目包含一些文件夹,如client
、config
、protocol
、server
,还有两个文件chat.json
和main.go
。我以为main.go
的作用类似于index.html
或类似的文件。
那么,我该如何在服务器上运行这个项目呢?
英文:
I have no experience on GoLang.
I have a Go project and I want to run it on my local server on my ubuntu 14.04. I have installed Go server and Go agent and they are running.
hesam: ~ $ sudo /etc/init.d/go-server start
[sudo] password for hesam:
using default settings from /etc/default/go-server
Started Go Server on http://hesam:8153/go
hesam: ~ $ sudo /etc/init.d/go-agent start
[Fri Nov 27 20:46:44 MST 2015] using default settings from /etc/default/go-agent
Started Go Agent.
hesam: ~ $
Based on what command line said /var/go/
is the folder that I can use to put my GO project inside. Based on what I know in Apache server there is www
folder that we will have access to from localhost. So, I'm expecting something like this with Go server (but seems I'm wrong).
My project contains some folders such as client
, config
, protocol
, server' and two files
chat.jsonand
main.go. I thought
main.goacts as
index.html` or similar.
So, how can I run the project on server?
答案1
得分: 4
go-server
和go-agent
是Go持续交付系统的一部分,绝对不需要来运行使用Go编程语言编写的程序。
实际上,你不需要任何东西来运行使用Go编写的已编译程序,因为它是静态编译的(默认情况下,也可以进行动态链接),这意味着所有必要的库都被放入可执行文件本身,可执行文件是自给自足的(在某些限制下,但这是一个边缘案例)。
因此,要运行一个Go程序,只需构建它并调用它,如下所示:
$ /path/to/programName
Hello, World!
(假设你构建了经典示例)。
请参阅如何编写Go代码获取详细信息。
英文:
The go-server
and go-agent
are part of the Go continuous delivery system and are absolutely not needed to run a program written in the Go programming language.
Actually, you don't need anything to run a compiled program written in Go, since it is statically compiled (by default, dynamic linking available), meaning that all necessary libraries are put into the executable itself and the executable is self sufficient (within certain limits, but that is an edge case, here).
So in order to run a Go program, just build it and call it like
$ /path/to/programName
Hello, World!
(assuming you build the classical example).
Please see How to Write Go Code for details.
gocd: http://www.go.cd "Website of Go Continuous Delivery"
golang: http://www.golang.org
wp:static: https://en.wikipedia.org/wiki/Static_build
答案2
得分: 0
运行golang程序可以使用go run
或go install
命令。如果你还没有设置go环境,你可以使用gvm或在Linux发行版上使用包管理器进行安装。
英文:
To run a golang program you can either do go run
or go install
. If you haven't setup go environment you can use gvm or on linux distro install using package manager.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论