简体   繁体   English

如何在 Go 服务器上运行 Go 项目?

[英]How to run a Go project on Go server?

I have no experience on GoLang.我没有使用 GoLang 的经验。

I have a Go project and I want to run it on my local server on my ubuntu 14.04.我有一个 Go 项目,我想在我的 ubuntu 14.04 上的本地服务器上运行它。 I have installed Go server and Go agent and they are running.我已经安装了 Go 服务器和 Go 代理,它们正在运行。

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.根据命令行所说的/var/go/是我可以用来放置我的 GO 项目的文件夹。 Based on what I know in Apache server there is www folder that we will have access to from localhost.根据我在 Apache 服务器中的了解,我们可以从 localhost 访问www文件夹。 So, I'm expecting something like this with Go server (but seems I'm wrong).所以,我期待 Go 服务器有这样的东西(但似乎我错了)。

My project contains some folders such as client , config , protocol , server' and two files chat.json and main.go . I thought我的项目包含一些文件夹,例如clientconfigprotocolserver' and two files chat.json and main.go . I thought . I thought main.go acts as index.html` or similar. . I thought main.go acts as index.html` 或类似的。

So, how can I run the project on server?那么,如何在服务器上运行项目?

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 . go-servergo-agentGo 持续交付系统的一部分,绝对不需要运行用Go 编程语言编写的程序

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).实际上,你不需要任何东西来运行用 Go 编写的编译程序,因为它是静态编译的(默认情况下,动态链接可用),这意味着所有必要的库都放在可执行文件本身中,并且可执行文件是自给自足的(在某些限制,但这是一个边缘情况,在这里)。

So in order to run a Go program, just build it and call it like所以为了运行一个 Go 程序,只需构建它并像这样调用它

$ /path/to/programName
Hello, World!

(assuming you build the classical example). (假设您构建了经典示例)。

Please see How to Write Go Code for details.有关详细信息,请参阅如何编写 Go 代码

To run a golang program you can either do go run or go install .要运行 golang 程序,您可以执行go rungo install If you haven't setup go environment you can use gvm or on linux distro install using package manager.如果您还没有设置 go 环境,您可以使用gvm或使用包管理器在 linux 发行版上安装。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM