Golang backend for MacOS?

xuanbao · 2017-05-06 13:14:42 · 660 次点击    
这是一个分享于 2017-05-06 13:14:42 的资源,其中的信息可能已经有所发展或是发生改变。

Hi everyone,

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.

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.

How do the applications communicate? How can I ensure the Golang backend is installed on someone's computer when they install the Swift UI?


评论:

fortytw2:

I would look into using buildmode=c-shared (or c-archive) and then call the archive from Obj-C/Swift. This should work on iOS, too :)

might be helpful - http://blog.ralch.com/tutorial/golang-sharing-libraries/

DyrusIsTheMan:

Perfect! That is super helpful. Thank you!

kjk:

If you want Swift calling Go code directly (as in being the same executable), you'll be in a world of hurt.

The way I built dbHero (https://dbheroapp.com) is:

  • the backend is written in Go and basically works as an http server (i.e. the UI is Web)

  • 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

  • Go executable is included in the resources directory of the .app bundle

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).

But that still will be painful because you'll have to serialize/deserialize all data that's going from Go to Swift.

tmornini:

Can you simply launch the go backend separately to serve an HTTP API locally?


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

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