How does golang fare in desktop applications?

blov · · 563 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I&#39;ve been working mostly in Java and TypeScript for the past year, and looking to expand my stack. So I went through Go Tour and while some of the syntax looks wierd for me, I must admit that elegance of go tool and concurency almost won me over. However go seems to be targeted mostly at web apps, and I wonder if there is any development focused on desktop use of go going on, and how well does it work on desktops now? </p> <hr/>**评论:**<br/><br/>kostix: <pre><blockquote> <p>web apps</p> </blockquote> <p>No, that&#39;s too narrow. It&#39;s primarily targeted at writing (networked) server-class applications. These days this indeed often means speaking HTTP, but not always—various RPCs are often used, and so are messaging systems. To sum it up, Go thrives in what is colloquially called &#34;the backend&#34;.</p> <p>As to the essense of your question, the answer is two-fold, I&#39;d say:</p> <ul> <li><p>No, the Go ecosystem does not currently has a &#34;rock-solid&#34; solution for desktop GUI. By rock-solid I mean both something like Tk, which is cross-platform albeit maybe a bit limited compared to more narrowly-scoped toolkits, and something like .NET&#39;s Winforms or WPF.</p> <p>There are various efforts with providing a solution which would not involve a 3rd-party GUI toolkit. The most visible one is supposedly <a href="https://github.com/golang/go/issues/11818" rel="nofollow"><code>shiny</code></a> and <a href="https://github.com/andlabs/ui" rel="nofollow"><code>github.com/andlabs/ui</code></a>.</p> <p>Both are far from being what you&#39;d typically call &#34;production-ready&#34;. But then there&#39;s the question of what level of functionality you need.</p></li> <li><p>On the other hand, there are working bindings to GTK3, Tk and Qt/QML.</p> <p>They work, but they lack the same level of integration with the rest of the runtime, say, Tk has with Tcl or WPF has with .NET. I mean, to build an app using these binding you need a working C (or C++—for Qt) compiler, and hence cross-platform development may be difficult. And you mostly loss the glorified property of no-brainer <a href="https://en.wikipedia.org/wiki/XCOPY_deployment" rel="nofollow">&#34;xcopy deployment&#34;</a> of programs written in Go—as in the case of using a 3rd-party GUI toolkit they start being linked with the dynamic libraries of that toolkit.</p> <p>For a list, you might start with <a href="https://github.com/avelino/awesome-go#gui" rel="nofollow">this</a>. The things it&#39;s missing for some reason are:</p> <ul> <li><a href="https://github.com/nsf/gothic" rel="nofollow">This integration with Tcl/Tk</a></li> <li><a href="https://github.com/go-qml/qml" rel="nofollow"><code>go-qml</code></a></li> </ul> <p>See also <a href="https://www.reddit.com/r/golang/comments/6dcu48/golang_gui_framework/" rel="nofollow">this</a> and <a href="https://www.reddit.com/r/golang/comments/4aqa9q/is_goqml_dead_anyone_using_it_in_production/" rel="nofollow">this</a>.</p></li> </ul></pre>tadvi: <pre><p>Go does not have solid desktop GUI solution. </p> <p>If GUI has to target only one platform it is not hard to build. I only ever needed to target Windows. It took about 2 months to build library that targets Win32 via syscalls. </p> <p>Result is this application: <a href="https://recoink.com" rel="nofollow">recoink.com</a></p> <p>Syscall lets you hook up message loop and do all regular Win32 SendMessage calls.</p> <p>There are also few specific <strong>tricks</strong> when building desktop GUI for Windows:</p> <ul> <li>Embedding icons into binary done via rsrc tool available on github.</li> <li>Building using &#34;go build -ldflags=&#34;-H windowsgui&#34; because you do not want command prompt open when app is launched.</li> <li>Redirecting log into a file.</li> <li>Error handling requires work since some errors need to be displayed to the user as pop ups or status bar messages.</li> </ul> <p>There is basic release.bat file example:</p> <pre><code>rsrc -manifest app.manifest -ico=app.ico,document_empty.ico,control_play_blue.ico go build -ldflags=&#34;-H windowsgui&#34; </code></pre> <p>Summary: Go can be used for GUI development. It works great. Unfortunately requires initial time investment to get whole foundation build up. I hope one day Go comes with solid libraries for desktop GUIs.</p></pre>kostix: <pre><p>Thanks for the insights.</p> <p>Unfortunately, recoink.com appears to be down for me. Am I correct that the product you&#39;re referring to is some OCR tool having been discussed, for instance, <a href="https://groups.google.com/forum/#!topic/Golang-Nuts/Vny646pRkgE" rel="nofollow">here</a>?</p></pre>vectorhacker: <pre><p>Go is a general-purpose language. It&#39;s well suited for lots of work, not just web apps. Being that it was designed in Google it was designed to handle many of the situations that arise in web and server programming very well, this is why the Go standard library has no many networking, encoding, templating, and other capabilities out of the box and why concurrency is so important in the language. </p> <p>That said, there&#39;s no reason from a language perspective why Go cannot be used to create robust desktop applications. One approach is that perhaps you shouldn&#39;t be writing the GUI components in Go, but instead use another language or framework for that, like C, C++ or an electron frontend, and have Go be the language that does the heavy lifting of your app&#39;s business logic. Go interfaces well with the C language after all, so there&#39;s no reason you couldn&#39;t use the C bindings for GUIs which almost every operating system and GUI library have.</p></pre>gac_web: <pre><p>Go is not capable of displaying any graphics without syscall hacks or C via CGO, so you need some external dependencies that are not coded in Go. So your best bet is to write a server and use whatever browser the user is using on his system to display a GUI. </p> <p>Frankly, most integration with third party GUI toolkits isn&#39;t very good. Sure, you can use Gtk for instance, then try to develop custom Gtk widgets with Go... it obviously does not work well.</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

563 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传