Seeking advice/guidance on frontend approach for golang backend api

xuanbao · · 681 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Hello gophers,</p> <p>I&#39;ve been working on a side project of sorts for a while now, specifically creating an API http server written in Go that I hope to use to power a user-facing webapp.</p> <p>The base of backend API is for all practical purposes written to consume the native net/http pkg&#39;s as close to possible with some basic 3rd party pkgs sprinkled here &amp; there for simplicity / not reinventing the wheel (i.e. routing, middleware, CORS etc.) as to avoid committing/consuming to one of the many more prescriptive web frameworks out there. The API outputs all requests in JSON as I decided to build with an API-first approach to solidify that foundation and then leverage it on a view component of my choice, e.g. webapp, mobile etc.</p> <p>I&#39;m now at the point that my backend is decent enough (basic models, db interaction, user + token creation) that I want to start rendering some of the view components as the API is handling the MC pieces of the MVC model, and I&#39;ve chosen to focus on a webapp over committing to a mobile app as that&#39;s just too much to handle at the moment for where I&#39;m at with the project.</p> <p>The issue though that I&#39;m stuck on is how to best proceed with implementing the frontend pieces. I&#39;ve looked into the Go templating language and that just feels clunky / lacking especially when my experience comes from the Django style of doing things - not the same stack, I know - but thats what I&#39;m kind of hoping to get close to. I&#39;ve also looked into ReactJS (as well as react-router + webpack) but the reality is that I&#39;m in way over my head and iterating with ReactJS, which consumes the API, is not as intuitive for me as I tend to have a more backend frame of thinking.</p> <p>I&#39;ve considered introducing Django into the mix strictly for the View piece of the MVC model, which would also be consuming my API, but I feel like i&#39;m going about it all wrong and potentially creating technical debt.</p> <p>What I&#39;m looking for in my frontend approach is the following:</p> <ul> <li>Reusability of code - think of a base HTML file with header / footer that I can extend for different pages (ala Django)</li> <li>Does not require its own server to serve the HTML content as I&#39;d really like to get to a static set of templates to then render with data (ala ReactJS w/o the steep learning curve)</li> <li>Insight into whether I should be leveraging a tool that does server-side rendering or client-side - I&#39;ve seen both sides of the discussion and though I lean towards client-side I&#39;m worried that concepts like the lacking of SEO content because everything is rendered by the client, as well as fully committing to a 100% javascript approach scares me a bit in terms of the webapp not being rendered at all if the user disables it in their browser</li> <li>Is fairly quick to pick up / learn</li> <li>Can be built-upon w/o having to scrap it all-together for something later on</li> </ul> <p>As I read this I&#39;m really thinking ReactJS + react-router is going to be my best bet long-term, but I just wanted to throw it out there to see what other options are at my disposal.</p> <p>Thanks!</p> <hr/>**评论:**<br/><br/>grounded042: <pre><p>IMHO, ReactJS is your best bet. You could use AngularJS, but then you can&#39;t do server side rendering (yet). With React, you can always implement the server side rendering down the road whereas transitioning from something like a straight server side MVC is a little bit harder. Step out and learn something new. You might feel a little bit out of your comfort zone, but once you start getting pieces working you&#39;ll feel great and will have picked up a new JS framework too. Plus, with React you can also potentially use React Native down the road for a mobile app.</p></pre>bamboogopher: <pre><p>This is great advice, thank you! React native is certainly a feature that has caught my attention.</p></pre>PaulCapestany: <pre><p>Personally I don&#39;t like how heavyweight React/Angular/etc are... I feel like I have a similar situation to you and I&#39;ve liked working with <a href="http://vuejs.org" rel="nofollow">http://vuejs.org</a> the most so far.</p></pre>bamboogopher: <pre><p>Interesting, I had never heard of Vue.js. What do you find easier about Vue compared to React/Angular etc.? Does it have a similar learning curve compared to React/Angular?</p></pre>PaulCapestany: <pre><p><em>Way</em> lower learning curve IMO. </p> <p>The Vuejs faq does a pretty good job explaining the differences and pros/cons between the other, more well-known frameworks: <a href="http://vuejs.org/guide/faq.html" rel="nofollow">http://vuejs.org/guide/faq.html</a></p></pre>grounded042: <pre><p>I&#39;d not seen vue before, but it does look like a good alternative to React and Angular - I&#39;ll be looking into it some.</p></pre>Ainar-G: <pre><p>I&#39;ve read your entire post and I still don&#39;t understand what your question is. Hell, there isn&#39;t even a single question mark! You seem to have troubles with choosing a front-end but I just can&#39;t see how this is Go-related.</p> <p>If you add an actual <em>question</em> to your post, people could try and answer that. Otherwise, people will just click &#34;expand&#34;, see a wall of text without a single &#34;?&#34;, maybe push an upvote button (meaning, &#34;I ain&#39;t reading all that but here&#39;s some to you for the effort&#34;), and go on with their day.</p></pre>bamboogopher: <pre><p>My apologies if my lack of punctuation and improper phrasing did not make my asks very clear - I rushed to create the post, but, I was simply trying to provide context to my situation rather than just plainly ask &#34;What frontend should I choose?&#34; I now see how this can be taken as just a &#34;wall of text&#34; and how it may or may not be considered relevant in this subreddit - I will keep this in mind for future posts.</p> <p>Though you&#39;re correct in stating that my decision for a frontend is not directly related to Go, it is a common situation that others are facing. Folks are looking to the language to facilitate the creation of more modular, concurrent, decoupled architectures, specifically, for the use of HTTP servers, and the lack of any formal direction from a frontend perspective still very much varies depending on who you ask.</p> <p>So with that said, given the perceived nature that the native template package does not seem to be as widely adopted amongst Golang developers compared to other non-Go options (Angular, ReactJS etc.), what frontend technologies &amp; approaches are you integrating into your stack if it is not Go templating? If I&#39;ve misinterpreted the stance on Go templating being used for substantially sized webapps, would you recommend they be a viable option to choose long-term?</p></pre>Ainar-G: <pre><p>Much clearer, thanks. First of all, I personally find Go&#39;s <code>html/template</code> good enough for almost anything related to server-side rendering. It&#39;s fairly simple, stable, not an external dependency, and since it&#39;s in the std, it&#39;ll stay that way as long as Go 1 exists.</p> <p>As for the front-end, I worked with Angular (on RoR projects though, not Go). It actually works fine, as long as you understand its logic, idioms, and set strict coding standards. The elephant in the room is Angular 2.0 that&#39;s going to basically break everything and switch to another language altogether (TypeScript), so good-bye to not scraping everything.</p> <p>I don&#39;t have a lot of experience with React (I&#39;m planning on playing with it on a side project). From what I saw and heard from others, it&#39;s pretty good as the &#34;V&#34; of &#34;MVC&#34;, but you still need to create (and sustain) &#34;M&#34; and &#34;C&#34; part of the architecture for yourself. React hasn&#39;t yet hit 1.0 though, so can&#39;t really say anything about its stability and future either.</p> <p>I&#39;ve also played with &#34;no-dependency&#34; approaches to front-end, like rendering everything on the server (a so-so idea, I just needed something working and quick) or using XML -&gt; XSLT -&gt; XHMTL chain (which actually worked well for a small-scale app), but I don&#39;t think I would recommend these for a modern web app, so it seems that React is the way to go these days.</p></pre>jasonrichardsmith: <pre><p>Please checkout my project <a href="http://mongolar.org" rel="nofollow">http://mongolar.org</a></p> <p>I am currently rewriting the backend to use etcd and vulcand.</p></pre>bamboogopher: <pre><p>Thanks! I&#39;ll definitely check Mongolar out</p></pre>

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

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