<p>I am thinking about options for building a cross platform app.</p>
<p>One Golang option would be gomobile. But adding a UI still means going native (Java / ObjC).</p>
<p>So I think another option would be a Cordova/Phonegap kind of solution, building the app in html/css/Golang. Using the mobile local browser (native on each platform) plus a webserver (in Go).</p>
<p>Is this possible ? Has anyone tried this ? Any considerations ? Maybe a sample project ?</p>
<hr/>**评论:**<br/><br/>JTandler: <pre><p>I am working on something quite similar. </p>
<p>We started to use gomobile to extend existing mobile applications (with native ui). Due some limitations in gomobile (when it comes to data exchange) we switched to use <a href="https://www.grpc.io" rel="nofollow">https://www.grpc.io</a> as a "data exchange layer" some time ago. So now the gomobile part provides a tcp/http2 endpoint and communicates with the native UI via grpc.</p>
<p>Although our setup is a bit different (using grpc), I can tell you that the basic architecture should work as you expect: Gomobile as embedded server with some native frontend (the webview in your case) is working fine.</p>
<p>Sadly I can not provide any sample code, but if you need any help feel free to ask. </p></pre>m3talsmith: <pre><p>One experiment I've tried is to write a gomobile sever and a react native client that both run on the phone (Android). The server was just a proxy to the backend and the client talked directly to the server running on the phone.</p></pre>caseynashvegas: <pre><p>I have lots of experience in mobile application development, both native and hybrid (cordova). By far I've found ReactNative to be the best of both worlds and one of the most productive environments.<br/>
My current big project uses React Native for the GUI and runs gomobile as a business and data tier on the device, which handles all the communication with my backend. </p>
<p>There are 3 decent ways to communicate between Go and React Native on the device, HTTP, Websockets and through the React Native Bridge. Here is a trivial example of each:
<a href="https://github.com/caseylmanus/go-react-native" rel="nofollow">https://github.com/caseylmanus/go-react-native</a></p>
<p>Feel free to ping me for details of that example if you can't figure it out, but it is self explanatory if you read both the gomobile and react native tutorials.</p></pre>shovelpost: <pre><blockquote>
<p>But adding a UI still means going native (Java / ObjC).</p>
</blockquote>
<p>That is not true. On the title you mention building a <em>web-based</em> App. Unless you mean something different, why do you need native UI for that? Yeah sure the native UI will be faster but the advantages of building a (non native) web-based app are very big. You essentially trade off the native feeling and speed for the cross-platform / write-once benefit which depending on your budget can be extremely beneficial.</p>
<p>For me the best way to do this right now is to have a solid and robust API on the back-end (written in Go) and use one of the available solutions for building a modern, mobile-first, progressive web app on the front-end that will consume the API. Personally I use <a href="https://www.youtube.com/watch?v=VBbejeKHrjg" rel="nofollow">polymer</a> for that but any of the other solutions will work.</p>
<p>Moreover, this gives you the benefit that if later you want to expand into a native app, you just create another front-end, this time on android / iOS that consumes the same Go API.</p></pre>1Gijs: <pre><blockquote>
<p>Unless you mean something different, why do you need native UI for that?</p>
</blockquote>
<p>Sorry for the confusion. I was talking about the case of using gomobile. In general that means using the gomobile native bindings to create a native UI on each platform.</p>
<p>I do not need a native UI so that is why I now consider a web app wrapped up for each platform. Like Cordova does.</p>
<p>I had the same ideas about dividing the code. As much as possible is already handled by a backend API. So the device part can be as thin as possible.</p></pre>beeker1121: <pre><p>My first project with Go and kind of React was making a mobile SoundCloud player. Main goal for it was to have it work well on mobile, since I'd be using it on my phone while driving 99% of the time.</p>
<p>Here is the <a href="https://github.com/beeker1121/resounden" rel="nofollow">GitHub link</a> for it, and here is the <a href="http://resounden.com/" rel="nofollow">live app</a>.</p>
<p>I wouldn't recommend following the structure of the app (the structure of the Go code, i.e. if I could redo it, I would code it almost exactly the same as <a href="http://tech.townsourced.com/post/anatomy-of-a-go-web-app/" rel="nofollow">this article</a> that was posted here instead of using the Model, View, Controller structure). However, you can resize your browser or open it up on mobile and see it works decently well.</p>
<p>The route I decided to go though is the second one you posted, just using the web browser. My app doesn't open as a native phone app though, rather you just browse to it like any other site. Doesn't seem to difficult to implement though, long as you can hook a browser API to load your site within the app.</p></pre>
Ask Reddit: Has anyone tried to build a web-based (html/css/Golang) App for mobile ?
blov · · 569 次点击这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传