使用Golang和Windows Server机器进行工作

huangapple go评论70阅读模式
英文:

Working with Golang and a Windows Server Machine

问题

我是一个中文翻译助手,以下是你要翻译的内容:

我是一个相对新手,对Go编程语言很感兴趣。我打算使用它来编写一个包含购物车的简单网站。

  • 如何在Windows服务器上安装Go语言?与普通计算机的安装过程相同吗?
  • 完成后,我应该采取哪些步骤来在Windows服务器上部署网站?
  • 在多大程度上需要使用HTML、CSS或JavaScript?
  • 我如何使网站在服务器上持续运行,以便我们网络/局域网中的其他用户可以访问它?

对于有关Web应用程序和/或Windows服务器的任何有用信息,我都表示感谢!

英文:

I am fairly new and interested in the Go programming language. I have the intention of using it to code a simple website that includes a shopping cart.

  • How to install golang on windows server? Is it the same process as a regular computer?
  • What steps do I take to deploy the website using the Windows server once it is finished.
  • To what extend is it required to use html, css, or javascript?
  • How can I keep the site running on the server for other users in our network/LAN to access it?

Any helpful information regarding web apps and/or windows server machines is appreciated!

答案1

得分: 5

这与一般的DevOps问题一样,也与Go语言有关。有很多需要考虑的因素,每个人的偏好也不同,但以下是我建议的一些指南:

  • 在生产服务器上安装Go工具链并不是必需的。这样你就需要在开发环境和生产环境都维护Go的安装,如果你的生产服务器与你的Windows电脑(如Linux发行版)使用的操作系统不同,这将很快变得混乱。相反,只需在本地开发并进行交叉编译以适应生产服务器的操作系统。
  • 你需要在生产服务器上保留与Go程序配合使用的数据库。
  • 然后,你可以通过sftp或其他方法将编译好的二进制文件和静态网页文件传输到生产服务器上。一旦二进制文件在生产服务器上,你可以在SSH连接中启动它,例如./programname
  • 根据你使用Go的方式,你不需要使用Apache。使用net/http包来提供Html、CSS和JS文件的服务。你可以在本地修改这些静态文件后再传输到服务器上,或者你可以将它们保存在Github仓库中,根据需要从生产服务器上进行git pull操作,前提是你已经在服务器上安装了git。
  • 通常情况下,你不需要担心在生产服务器上保持程序的“运行”。http.ListenAndServe会监听指定端口上的请求。如果服务器重新启动或关闭,你可以自动启动编译好的二进制文件。

你还可以使用Vagrant、Virtual Box和Ansible等工具来高质量模拟你的生产环境,并根据你的需求创建新的服务器。

英文:

This is as much a general dev ops question as it is specific to Go. A lot of things to consider here and everyone will have varying preferences but here are some guidelines I'd recommend:

  • It's not necessary to install the Go tool chain on your production server. You then have to maintain your Go installation on both your development and production environments and if your production server is a different OS than your Windows computer (eg. a Linux distribution) this will get out of hand quickly. Instead, just develop on your local and cross compile to the OS of your production server.
  • One thing you will need to keep on your production server is whatever DB you choose to work with your Go program.
  • You can then sftp or transfer through a method of your choice your compiled binary over to your production server along with your static web files. Once the binary is on your production server you can fire it up when you're SSH'ed in eg. ./programname
  • Depending on how you want to use Go, you don't need Apache. Use the net/http package to serve up your Html, CSS and JS files. You can transfer these static files over after you've worked on them on your local or you can just keep them in a Github repo and git pull them from your prod server as needed, assuming you've installed git there.
  • You generally don't need to worry about keeping it "running" on your production server. http.ListenAndServe listens on your port for incoming requests. If your server reboots or shuts downs you can automatically have your compiled binary start up along with it.

You can also work with things like Vagrant, Virtual Box and Ansible for high quality mimicking of your production environment and spinning up new servers according to your desired specs.

huangapple
  • 本文由 发表于 2016年11月7日 09:57:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/40456757.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定