Example of golang serving node.js http requests

polaris · · 270 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I&#39;ve tried finding examples of this but all I find when googling nodejs and golang together are articles comparing benchmark speeds. I&#39;m trying to setup a basic development environment with two servers. One being a nodejs server that makes requests and gets responses from a golang server. Help me out please</p> <hr/>**评论:**<br/><br/>itsmontoya: <pre><p>What you&#39;re speaking of sounds like a simple API. What are you trying to communicate exactly?</p></pre>_BubbaGump_: <pre><p>I want to design nodejs as the first layer of servers that capable of handling universal javascript and have golang be the api server layer. I&#39;m just trying to design a basic <code>Hello world</code> with this architecture</p></pre>itsmontoya: <pre><p>Sounds convoluted. Why not just write the entire backend in go?</p></pre>PaluMacil: <pre><p>Chances are that a website would craft JSON for the request to the server and then Node would send the same JSON to Go (it&#39;s a great format for any language to send or receive data), so I think we&#39;re all missing what you want Node in the middle to do.</p> <p>You mention universal JavaScript, which I assume means you have a specific bit of work you&#39;d like to accomplish in the server, but if you can explain what this needed functionality is, we can probably point to a Go solution so that you won&#39;t need to have multiple server apps for a simple application.</p></pre>joncalhoun: <pre><p>It sounds like you want JavaScript making HTTP requests to a go server and getting responses to do something with them. </p> <p>The problem I&#39;m guessing you are having in is that node.js and golang are both server side things. What you likely want is some client side JavaScript (or really any job at all) making http requests to a golang server. </p> <p>Even if that isn&#39;t what you want, you don&#39;t <em>have</em> to do both at once. First you need to learn to use golang to serve request (probably json?). Then you need to independently learn to make http requests to a server with JavaScript. Then you just use js to create a request to a url that maps to your golang server. </p> <p>If you could shed a little more light on your goals it would be possible to get more specific than that, but with what you have provided j think that&#39;s about as detailed as I can get.</p></pre>Swarengen: <pre><p>node.js is the worst fuckin thing that has ever happened to computing. pls stop.</p></pre>shark1337: <pre><p>Pls stop, if you don&#39;t know about it, don&#39;t say bs here</p></pre>

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

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