Hey Gophers, a newbie has a question for ya

agolangf · · 446 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I&#39;ll be upfront, I suck at Golang. It&#39;s one of the first &#39;hard&#39; languages I&#39;ve chosen to learn, so I may ask some stupid questions. Please bear with me here.</p> <p>I am writing a web application that involves 4 different components. I&#39;ll write my idea for implementation with each, and if its a terrible, terrible idea, I would appreciate it if ya told me.</p> <p>.</p> <p><strong>Query an API to receive price data</strong></p> <p>Pretty much the easiest portion so far, just query with an already build golang api</p> <p><strong>Accounts</strong></p> <p>Generate salted hashes using golang.org/x/crypto/bcrypt and store them on an SQL table</p> <p><strong>Live charting of price</strong></p> <p>This is where I&#39;m having a hard time. I plan to use ChartJS for the physical charting, but I can&#39;t pin down how to fetch the prices live and keep them updating. My only idea was to constantly iterate through a list of items that the user has bought, and renew their data on an SQL table, and have the chart draw from that (seems like it would be a god awful and slow idea, but I cant think of anything else)</p> <p><strong>Tracking of account &#39;payments&#39; (its a sandbox env for buying/selling)</strong></p> <p>I figured using golang to do the basic calculations for net worth and whatnot would be fine, and store them back to the SQL table.</p> <p>.</p> <p>I was wondering if anyone had any advice to give me related to tying in golang to this site.</p> <p>My two ideas so far were to query with AJAX, or to write the entire thing with the Go net/http package. It will have an audience of about 5-6 users ever, its pretty much purely a learning experience, but I still want to do it right.</p> <p>(I would just like to make it clear that this is a personal project, I&#39;m not trying to skate past doing work or whatnot, just a little noob lookin for a direction to go in)</p> <p>Mods, I couldn&#39;t tell if you allowed posts like this so sorry in advance.</p> <hr/>**评论:**<br/><br/>seankhliao: <pre><p>You can use websockets to keep an open connection and just periodically write the data to live stream it</p></pre>kardianos: <pre><p>Yeah, just do either a periodic query with JS AJAX or to a long poll with ajax (you make a request, then you block in the net/http request handler until something interesting happens). I&#39;d avoid websockets for something like this.</p> <p>For the live prices, make a http handler that takes a list of IDs (user needs updated prices for all of these IDs), query them in a single query, and return them all at once. After you do this on the client, do a JS <code>setTimeout(FetchAgain, 5000);</code> .</p></pre>

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

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