Help with Web App Problem

agolangf · · 490 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>So I was following along on Pluralsight with a making web apps in Go. I got to a point where trying to run the app from the terminal in OSX. I have run this same code on Windows and it works fine, but for some reason on OSX the connection doesn&#39;t stay open when it do &#39;go run main.go&#39;. So why is it any different running it in Windows and OSX? Can anyone help me with why this code isn&#39;t keeping it open so I can navigate to localhost:8080? Like in windows the app keeps running until I use control + c to stop it while on OSX it just stops like immediately. Here is a pastebin of the code. </p> <p><a href="http://pastebin.com/fgm3hkFz" rel="nofollow">http://pastebin.com/fgm3hkFz</a></p> <p>Thanks!</p> <hr/>**评论:**<br/><br/>adampresley: <pre><p>Issue #1 I see, right off the bat, is you have your ListenAndServe() method inside of your handler function. That should be outside of it.</p></pre>jayjuicejay: <pre><p>Thanks. Pretty much guarantee that was the issue. I did not notice that. ;) As you can see I retyped the code and did not use the exact code from Windows as this would not have worked there either. I now feel like an idiot.</p></pre>j1436go: <pre><p>Updated: <a href="http://pastebin.com/ii7qg0q9" rel="nofollow">http://pastebin.com/ii7qg0q9</a></p></pre>jayjuicejay: <pre><p>Figured it out. 1st Issue: ListenAndServe() was within the handler function which it should not have been. 2nd Issue: Was checking for err != nil when should have been checking if err == nil. Thanks for everyone who helped much appreciated!!</p></pre>

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

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