Goland 远程开发设置

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

Goland remote development setup

问题

我正在开发我的第一个Go项目,需要在远程Linux服务器上进行开发。这是一个小项目,所以我需要一个非常简单的解决方案,但是我已经尝试了3天,仍然无法成功设置我的Goland。开始怀疑是否需要在这里使用它。

我已经设置好了SSH终端和SFTP。问题是我不确定如何在本地编写代码,本地构建并上传到服务器,或者在服务器上构建。这是我尝试过的方法:

1)尝试使用远程文件管理器和远程终端,只使用Goland作为编辑器进行开发。问题在于,如果Goland遇到一些缺少的包,它会给我报错,也许我可以忽略这个错误?

2)尝试在本地编写代码,每次保存后与远程同步,并从终端编译。但是这会导致缺少包的问题,但总体上它是可行的。

3)尝试在本地编写代码,然后从运行选项中远程编译。问题在于,我想在本地编写我的install.go文件,并将其上传到/root/project/install作为编译后的文件,但它会创建一些临时文件,甚至尝试从"Go工具参数"中覆盖我的-o文件,但它只是将路径添加到现有文件中。

4)尝试在本地编写代码并在本地编译,然后将其上传到服务器,但是完全找不到这样的方法。

5)也许可以尝试使用dlv,但它看起来像一个简单的问题,希望我不必因此在服务器上安装额外的软件。

这些选项中有哪些是有效的,或者我还漏掉了其他选项?希望你明白我真正想要的是什么。

提前感谢你!

英文:

Im developing my first go project and i need to develop it on a remote linux server. Its something small and this is why i need something really simple, but 3rd day now im trying to setup my goland with no success. Starting to wonder if i need it at all here.

I already setup my SSH terminal and my SFTP. The problem is that im not sure how to write my code locally, build it locally and upload to the server or build it on the server. This is what i tried:

  1. Tried to develop with remote file manager and remote terminal, just using goland as editor. The problem here is that if goland meets some missing package, it will give me errors, maybe here i can somehow ignore this?

  2. Tried to write it locally, sync with remote on every save and compile it from the terminal, but this will create an issie with missing packages, but in general it works.

  3. Tried to write it locally, compile it remotely from the Run options. The problem here is that i want to write my install.go file locally and upload it to /root/project/install as compiled file, but its creating some temporary files, tried even to overwrite my -o file from the "Go tool arguments", but it just adds the path to the existent one.

  4. Tried to write it locally and compile it locally and then upload it to the server, but cant find the way for such thing at all.

  5. Maybe dlv, but it looks like a simple issue, hope i wont have to install additional software on the server because of this.

Is some of those options valid or im missing another options? I hope you understood what i really want.

Thank you in advance!

答案1

得分: 2

> 但是第三天了,我一直在尝试设置我的Goland,但一直没有成功。开始怀疑我是否真的需要它。

你不需要它。

> 4. 尝试在本地编写并在本地编译,然后将其上传到服务器,但是完全找不到这样的方法。

这就是你想要的。你只需要在服务器上安装go build生成的可执行文件,该文件是为服务器的架构构建的,你可以通过SFTP复制过去。

当你想要在本地运行程序时,你可以使用go build生成可执行文件并运行它。

当你为远程服务器构建时,你需要设置GOOSGOARCH为适合服务器的值:

GOOS=linux GOARCH=amd64 go build -o my-project.linux-amd64 

如果你的服务器是ARM架构,将amd64替换为arm64

然后将my-project.linux-amd64复制到服务器上,它就能够在那里成功运行。

> 我正在开发我的第一个Go项目

那么请确保理解这一点:Go可执行文件在运行时不需要Go库

这是Go的一个重要优点,与解释型语言(如Python、JavaScript、Ruby)以及运行在软件虚拟机(如JVM(Java)或基于BEAM的Erlang虚拟机)的语言不同。

作为Go的新手,请确保阅读教程

在开发第一个项目时,立即编写测试,这将是你展示功能的主要方式。

英文:

> but 3rd day now im trying to setup my goland with no success. Starting to wonder if i need it at all here

You don't need it.

> 4. Tried to write it locally and compile it locally and then upload it to the server, but cant find the way for such thing at all.

This is what you want. The only thing you need to install on your server is the executable from go build, built for the server's architecture, which you can copy over SFTP.

When you want to run your program locally, you will use go build to produce an executable that you can run.

When you build for the remote server, you will want to set GOOS and GOARCH to the values appropriate for your server:

GOOS=linux GOARCH=amd64 go build -o my-project.linux-amd64 

If your server is ARM, substitute arm64 for amd64.

Then copy my-project.linux-amd64 to the server and it will be able to successfully run there.

> Im developing my first go project

Then make sure to understand this point: go executables don't need go libraries at runtime.

This is a big selling point for Go, and is different from an interpreted language like Python, Javascript, Ruby, and also different from languages that run in a software virtual machine like JVM (Java) or BEAM (Erlang) baed VMs.

As a newcomer to go, please make sure to read the tutorial.

Save yourself a lot of hassle and Write tests right away as you develop your first project. These should be your primary way of demonstrating functionality as you work on your project.

huangapple
  • 本文由 发表于 2021年11月25日 07:41:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/70104240.html
匿名

发表评论

匿名网友

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

确定