Reinventing Wheels

agolangf · · 524 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Hey <a href="/r/golang" rel="nofollow">/r/golang</a> - I&#39;m a full stack (BI) developer and my employer has passed on the opportunity to monetize an internal solution and I asked for and was granted permission to work on it on the side.</p> <p>The employer solution is built with php and jQuery, and I&#39;m evaluating different frameworks- 1. So there is no code similarity and 2. Compiled binaries are advantageous compared to scripted languages in terms of distribution and customer base</p> <p>Golang looks like an obvious choice for the backend, but it&#39;s not a web development language, it&#39;s general purpose, and running a web application means first replicating all the standard components of a web server</p> <p>I can see there are standard libraries, but are there plugins like mod_go so I can point to /application/myApp.go and offload things like hostname/TLS/static files to Apache?</p> <hr/>**评论:**<br/><br/>itsmontoya: <pre><p>I think you really need to rethink your entire concept of the software stack. I feel like PHP has poisoned the minds of many developers who don&#39;t realize there are MUCH better ways to do things. No need to use Apache anymore, go can handle tons of requests without the need for an intermediary proxy. </p></pre>lluad: <pre><p>There&#39;s no reason to use apache to host a Go webapp. The standard library server will do just fine. If you <em>do</em> want another webserver in front of it for some reason the easiest thing to do is use it as a proxy, but I wouldn&#39;t bother unless I had specific requirements (e.g. serving it embedded at a path within an existing website or something like that).</p> <p>You&#39;ll find that the standard library http server and html/template give you most everything you&#39;d want in a web development language, and there are a lot of decent third party libraries to fill in the gaps should you need them.</p></pre>alaskacodes: <pre><p>It&#39;s not quite as cut-and-dry as this if you&#39;re going to be exposing a go service directly to the big, bad Internet. I recommend reading <a href="https://blog.gopheracademy.com/advent-2016/exposing-go-on-the-internet/" rel="nofollow">Filippo&#39;s post</a> on the subject. I&#39;m working on a <a href="https://github.com/alaska/shttp" rel="nofollow">little library</a> to make these best practices as easy as possible to spin up, but I haven&#39;t had time to work on it in months. As soon as I&#39;ve caught up and had the time to integrate autocert, it should be a good shortcut.</p></pre>titpetric: <pre><p>There&#39;s also some performance issues with TLS (https) - citation needed as I&#39;m replying on phone, and having a nginx proxy is generally a good idea anyway, because you can easier handle vhosts, CORS headers, caching, etc.</p></pre>j-aubry: <pre><p>Great answer, I&#39;ll give it a shot- thanks! </p></pre>earthboundkid: <pre><p>You can easily serve your static files with Go: <a href="https://godoc.org/net/http#example-FileServer" rel="nofollow">https://godoc.org/net/http#example-FileServer</a></p> <p>Or just have your Go app run on a random port and then do a reverse proxy to it from Apache/Nginx if you feel like putting something in front of Go for rate limiting.</p></pre>SeerUD: <pre><p>A lot of the use-cases I&#39;ve seen for using Go at the moment have either been for CLI tools, or web services (i.e. not web applications). I think Go is perfectly capable at making web applications, but many people choose to use it as a web service backend, and then use a JavaScript client-side front-end.</p> <p>With regards to things like <code>mod_go</code>, that&#39;s not how Go works. Go <em>is</em> the server, unlike with a language like PHP. It&#39;s not necessarily recommended to expose a plain, unconfigured Go server out at the internet though. You can either learn about the options you&#39;d need to set to make Go able to do that, or you can whack something like Nginx or HAProxy in front of it.</p> <p>Many people deploy Go web services/apps as Docker images because it&#39;s incredibly easy to package them up, they run quickly, and the image size is tiny.</p></pre>AzusaD: <pre><p>Go can 1,000% be used for web development. I&#39;m not sure where you got the information that it wasn&#39;t a web development language. In fact, Go is the easiest language I&#39;ve ever come across when it comes to web development. The standard library has tools for marshalling JSON and XML, spinning up performant web servers, incorporating SSL/TLS, implementing APIs, hosting static pages, and there&#39;s even text and HTML templating built right in. I&#39;d suggest the book called Web Development with Go by Shiju Varghese for a hands on guide to web development in Go. There are plenty of resources on the Go website about getting a basic web app setup. Also, if you&#39;re into frameworks check out Buffalo or Gin. I&#39;d suggest not using a framework though, but the option is there.</p> <p>Edit: fix typos</p></pre>diosio: <pre><p>Or gorilla, which is a more library like alternative!</p></pre>

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

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