Thoughts on gin?

blov · · 372 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I wanted to try something new instead of the built in http package. There aren&#39;t many frameworks for Go and I know they are mostly discouraged but gin looks good and have 14K stars so I hoped to hear your thoughts and review on it.</p> <hr/>**评论:**<br/><br/>earthboundkid: <pre><p>I prefer <a href="https://github.com/go-chi/chi">https://github.com/go-chi/chi</a> but really it doesn&#39;t matter too much. </p> <p>Ignore Github stars. The question is &#34;is this software sufficiently maintained for me to rely on it?&#34; That can be true even with 0 stars and false even with 1 million stars (see OpenSSL for a non-Go example of widely used unreliable software).</p></pre>pinpinbo: <pre><p>Another upvote for chi. I don&#39;t prefer routing framework that doesn&#39;t use <code>HTTPHandler()</code> interface or if they invent their own <code>Context</code>.</p></pre>FPSports: <pre><p>I&#39;m slightly confused about people comparing Chi with Gin.<br/> Gin is a framework, which uses <a href="https://github.com/julienschmidt/httprouter">httprouter</a> as a router.</p> <p>Chi is &#34;just&#34; a router with some middleware.</p> <p>You can&#39;t compare those 2 as they don&#39;t serve the same purpose and you surely can&#39;t recommend one over another.</p> <p>For OP: what&#39;s wrong with the http package? Why do you want to try something new? When I first started doing stuff in Go I was looking for a framework as well, coming from PHP/Symfony2 I was used to that approach. I&#39;ve been through nearly every framework Go has to offer... at some point I was always hitting a wall deciding that I&#39;m not gonna use that particular framework. The standard-library+a proper router (like Chi) serve me well these days and so far I&#39;ve not caught myself looking for a framework again. On the opposite, I&#39;m in the middle of writing my own little framework that helps me develop faster. Also helps me learn Go a bit more.</p></pre>MikeTheShowMadden: <pre><p>You can compare them for OP, as it seems OP doesn&#39;t really know the difference between a library, framework, or what have you.</p> <p>Either way, he can offer Chi as an alternative as it <em>seems</em> like it would suffice the OPs needs since he didn&#39;t specify needing anything gin offers over Chi. It sounds like he just wants to make a rest service quick, and Chi looks like it can do that.</p></pre>aboukirev: <pre><p>Both are frameworks that come with router, middleware chaining, route and parameters parsing, form binding, rendering HTML/XML/JSON, logging, graceful shutdown, and variety of useful middleware. They just have it organized a bit different: some is sub-packages, some contrib packages, under the same project or in a different project under the same Github account. </p></pre>necrosexual: <pre><p>For me I&#39;d rather use gin that http because I&#39;ll be just writing code that someone else has already written, and written better than I could write it.</p></pre>Tikiatua: <pre><p>Gin is a great framework and we used it a lot in the beginning. However we have since switched to <a href="https://github.com/labstack/echo">https://github.com/labstack/echo</a> and are very satisfied with the functionality it provides without trying to do too much.</p></pre>aboukirev: <pre><p>I&#39;ll second that. <code>echo</code> is straightforward and has enough features while not being overloaded. I have half a dozen projects using it. It is non-idiomatic. But that also makes it more elegant, concise. <code>gin</code> is non-idiomatic too. </p> <p>If you want a small fast idiomatic framework, look at <a href="https://github.com/go-chi/chi">https://github.com/go-chi/chi</a></p></pre>VirmundiUndead: <pre><p>Kind of on topic: why not look at gRPC? Are you really doing restful design, ie HATEOAS? If not, why not a binary, documented protocol that&#39;s supported by the majority of programming languages including Go and JavaScript?</p></pre>yotamN: <pre><p>I&#39;m actually not creating restful server but a server that returns html pages.</p></pre>VirmundiUndead: <pre><p>Like just serving? If so, why not learn nginx? You&#39;ll get to learn about services, and configurations, but get a really quick, custom built problem solver. The reason I pry is to see if you&#39;re using the best thing for a problem. Don&#39;t get me wrong, Go for the sake of Go is nice too. I just want to do my part to avoid a not-made-here mentality.</p></pre>yotamN: <pre><p>No, they are dynamic (I think this is the correct term). I use the template package to generate the html files with data from the database.</p></pre>VirmundiUndead: <pre><p>That is the correct term. Thanks for asking the questions.</p></pre>014a: <pre><p>If you&#39;re serving static HTML, you should really just use <code>http.FileServer</code>. Or nginx. Or, host the files on S3 and enable Static Website Hosting (this option is huge, more people need to use this). </p></pre>zpatrick319: <pre><p>People typically discourage new Go developers from using web &#34;frameworks&#34; because it&#39;s valuable to understand Go&#39;s http standard library before jumping into someone else&#39;s abstraction. Often times, for small projects at least, the standard library has everything you&#39;ll need.</p> <p>That being said, you&#39;re going to find common tools/patterns/features useful as you write more web applications. Once you&#39;re operating in that context, you can either:</p> <p>A) Be a &#34;no framework purist&#34;, which would require you to copy+paste tools/patterns/features from project to project.</p> <p>B) Use someone else&#39;s package that has the tools/patterns/features you find useful, e.g. gin. </p> <p>C) Create your own package that has the tools/patterns/features you find useful. </p> <p>awesome-go is a great resource for checking out go projects, and has a section of web frameworks and middleware: <a href="https://github.com/avelino/awesome-go#web-frameworks" rel="nofollow">https://github.com/avelino/awesome-go#web-frameworks</a> </p></pre>heartwilltell: <pre><p>Maybe you should look at <a href="https://github.com/gobuffalo/buffalo" rel="nofollow">https://github.com/gobuffalo/buffalo</a></p></pre>

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

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