<p>Hi everyone, </p>
<p>I'm trying to develop an application in such a way that I would have a Golang Backend (Core, SDK, whatever it would properly be called), and then use a Native Swift UI. </p>
<p>I have a lot of questions about this specific setup, and I've attempted to do quite a bit of research but came up empty. If anyone has any experience doing this I would like to be pointed in the right direction.</p>
<p>How do the applications communicate? How can I ensure the Golang backend is installed on someone's computer when they install the Swift UI?</p>
<hr/>**评论:**<br/><br/>fortytw2: <pre><p>I would look into using <code>buildmode=c-shared</code> (or c-archive) and then call the archive from Obj-C/Swift. This should work on iOS, too :) </p>
<p>might be helpful - <a href="http://blog.ralch.com/tutorial/golang-sharing-libraries/" rel="nofollow">http://blog.ralch.com/tutorial/golang-sharing-libraries/</a></p></pre>DyrusIsTheMan: <pre><p>Perfect! That is super helpful. Thank you!</p></pre>kjk: <pre><p>If you want Swift calling Go code directly (as in being the same executable), you'll be in a world of hurt.</p>
<p>The way I built dbHero (<a href="https://dbheroapp.com" rel="nofollow">https://dbheroapp.com</a>) is:</p>
<ul>
<li><p>the backend is written in Go and basically works as an http server (i.e. the UI is Web)</p></li>
<li><p>the Mac app is a trivial Swift app that uses WebView that starts the Go executable at start and simply loads the url that Go app</p></li>
<li><p>Go executable is included in the resources directory of the .app bundle</p></li>
</ul>
<p>If you really want to write native UI in Swift (as opposed to building a web app), then you could still have a separate Go executable and communicate via some reasonable protocol e.g. protobufs over network (maybe gRPC if there is a Swift library for it).</p>
<p>But that still will be painful because you'll have to serialize/deserialize all data that's going from Go to Swift.</p></pre>tmornini: <pre><p>Can you simply launch the go backend separately to serve an HTTP API locally?</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传