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:
DyrusIsTheMan: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/
kjk:Perfect! That is super helpful. Thank you!
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?
