<p>EDIT:</p>
<p>as a clarification: I am not looking for the same dynamic metaprogramming shenanigans that ruby offers...... I'm just looking for frameworks and packages that do specific things. </p>
<hr/>
<p>Hey all, I'm super interested in Go, and am wondering what packages are out there could be put together to try to get as close to the rails experience (tm) as possible. (basically just developer ergonomics, and heavy convention over configuration).</p>
<p>The main things I'm looking for when building an API:</p>
<ul>
<li>ActiveRecord-like interface to interacting with models
<ul>
<li>has_many through is a relationship option I don't see in many non Rails AR ORMs.</li>
</ul></li>
<li>Serializers (ActiveModelSerializers) - These are basically just a presenter that formats your objects into JSON API or some other format for rendering.</li>
<li>easy User management / integration with JWT (see: Devise / Auth0)</li>
<li>Pre-configured logging
<ul>
<li>Database Queries</li>
<li>Request/Body Parameters</li>
<li>Errors</li>
<li>Logging of Stack trace upon error</li>
</ul></li>
<li>Before Filters on controller actions</li>
</ul>
<p>Thanks!</p>
<p>I'm excited to see what Go has to offer!</p>
<hr/>**评论:**<br/><br/>UnknownTed: <pre><p>My recommendation is to use separated libraries for each task.</p>
<p>If you wanna get the best that Go has to offer, try these together:
<a href="https://www.reddit.com/r/golang/comments/4tt16b/is_this_a_reasonable_set_of_choices_for_web_dev/d5kbvjz" rel="nofollow">https://www.reddit.com/r/golang/comments/4tt16b/is_this_a_reasonable_set_of_choices_for_web_dev/d5kbvjz</a></p>
<p><del>or not, <a href="http://beego.me/" rel="nofollow">http://beego.me/</a></del></p></pre>DerNalia: <pre><p>thanks!</p></pre>go_nut: <pre><p>You'll never get close to the Rails experience. Go rigidity disallows it, which is considered a feature by some people who code in Go. You can resort to code generation though you'll have to write manifests in a third party format and write/use code generators.</p>
<blockquote>
<p>ActiveRecord </p>
</blockquote>
<p>There are a few ORMs like Gorm, Xorm, you'll quickly realize that you can't write complex queries with them, they are merely useful for persisting values. Go limitations also make writing a query builder difficult.</p>
<blockquote>
<p>Serializers</p>
</blockquote>
<p>You don't need that. If a type needs to be serialized into a different structure then write another type that will be the view for the former type. For instance</p>
<pre><code> type Foo struct {}
func(f Foo)ToFooFiew(){ /* code */ }
type FooView struct {} // type used for serialization
</code></pre>
<blockquote>
<p>Auth </p>
</blockquote>
<p>there is a package called auth-boss I believe</p>
<blockquote>
<p>Before Filters on controller actions</p>
</blockquote>
<p>There are some middleware queues like alice and negroni , you can't create a class like in Ruby, write blocks and write filters that way.</p>
<p>do a quick search on godoc.org to look up for other stuffs you might need.</p>
<p>There are few frameworks in Go, like revel or beego, I never used them, and routers like sinatra (httprouter,gorilla toolkit,...).</p>
<p>Go is all about types, and will shove that fact in your face everytime you try to do something "smart". Ruby style programming is impossible with this language, be warned.</p>
<p>To sum up, if you really want to work like Rails, write code generators to generate go code from YAML manifests. Other wise write specific code because Go will compele you to do so.</p></pre>DerNalia: <pre><p>this is exactly the response I was looking for, thanks!</p>
<p>I'm aware of how typed Go is, and I have experience with middlewars (asp.net, express.js).</p>
<p>I think the <em>ideals</em> of rails are possible in any language. Of course the way things are done is going to be different, but that doesn't mean I can't have conventions or developer ergonomics. It just means they're different.</p>
<p>Thanks for the info, I think when I find time, I'll see if I can build an app prototype that fits my requirements.</p></pre>go_nut: <pre><p><a href="https://github.com/avelino/awesome-go" rel="nofollow">https://github.com/avelino/awesome-go</a></p>
<p>you can check it, for a good list of useful libs too.</p></pre>hjkelly87: <pre><p>I haven't used it myself — I work for a company with a large code base that would be a pain to migrate — but if I were to start an API project, I'd probably try out Goa: <a href="https://goa.design/" rel="nofollow">https://goa.design/</a></p>
<p>One thing that sets it apart (at least from what I've found) is the endpoint design step that can be used to auto-generate API docs. I'm not sure how the rest of it works, though.</p>
<p>In general, you may find that the Go community leans toward connecting several tools yourself rather than adopting a scaffolding (like Rails or Django, where I come from) with pluggable modules that just work. I don't say that too confidently, though, because like I said I haven't had a chance to use frameworks myself.</p></pre>supertopher: <pre><p>I'm coming from Rails and Goa is a good stepping stone to learn from how to structure an application and plugin any libraries. It will create controllers, types you can use for serialization in requests and responses, a swagger file, an example Javascript client, authentication (JWT, OAuth, others as well). It uses a DSL which isn't that hard to grok after staring at it long enough, haha. The small amount of code you write in the DSL it generates some very nice idiomatic Go code. All you have to do after is either use Gorma or plugin your own database (SQLX, Gorp, Xorm, whatever you like). The outputted code is easy to follow and understand and you can always re-generate. Even the Goa code itself is easy to understand and small enough a beginner like me can get in their and dirty or write plugins using the DSL.</p></pre>DerNalia: <pre><p>thanks for the link! this looks interesting!</p></pre>typing_cod: <pre><p>I'm from Rails and starting to play with Go. I found that you'll need to combine specific libraries, like using pg for the as an ORM for Postgres as opposed to using something general like ActiveRecord.</p>
<p>I've been liking gin for the web server and routing, it's very similar to Sinatra. I've just using the builtin Go templates for the HTML responses.</p>
<p>I think revel, might be the closest to Rails with a lot of functionality. I haven't tried it yet.</p></pre>fortytw2: <pre><p>No matter what you do, you won't get anything like the rails experience in Go -> use rails for what it's great at, use Go for what it's great at, and don't try to force one to be the other </p></pre>DerNalia: <pre><p>Why can't Go be good at what rails is good at? (providing a great developer experience and convention over configuration).</p>
<p>Any language should be able to provide that. :-\</p></pre>dlsniper: <pre><blockquote>
<p>Why can't Go be good at what rails is good at? (providing a great developer experience and convention over configuration).
Any language should be able to provide that. :-\</p>
</blockquote>
<p>Go can provide a great user experience, but you have to glue together the pieces you need. Using things like gorilla/mux, spf13/viper, jmoiron/sqlx and a few other things will give you an unmatched degree of flexibility and control.</p>
<p>What Go cannot to do out of the box like all the dynamic languages (Ruby, PHP, etc.) is give you a generic framework to stuff everything in and hope for the best. That approach doesn't work particularly well because of the type system (which is inflexible for this particular case) and the fact that Go users prefer type safety and explicit dependencies vs ambiguity.</p></pre>DerNalia: <pre><p>I made an edit to my OP</p></pre>dlsniper: <pre><p>I've named a couple of things already that should get you far way. It really depends on your needs. For example markbates/goth is amazing at providing authentication with various providers, lib/pq is the PostgreSQL driver of choice, spf13/cobra is excellent for cli arguments and so on. </p>
<p>I think the question is not particularly great worded and that might spark some heat in gophers but if you seek any further help I also recommend the Slack room (invite link <a href="https://invite.slack.golangbridge.org/" rel="nofollow">https://invite.slack.golangbridge.org/</a>) </p>
<p>Hope it helps. </p></pre>very-little-gravitas: <pre><blockquote>
<p>Why can't Go be good at what rails is good at? </p>
</blockquote>
<p>There's absolutely no reason it can't be. I'm writing similar apps to those I write in Rails (or have written, mostly writing Go now) with few problems. It's certainly possible and there are lots of useful libraries available for most of the things that Rails provides out of the box, particularly for writing APIs. </p></pre>DerNalia: <pre><p>Thanks! I'm glad there are calm people in this community and it's not all 'hate rails, and can't think creatively' :-)</p>
<p>I had a pretty negative first 30 minutes with this post :-(</p></pre>skidooer: <pre><p>I would argue that Go is significantly better than Rails (at providing web APIs, which seems to be what you are wanting to do here).</p>
<p>But it is better because it approaches the problem in a completely different way. If you just want to emulate Rails, why not use Rails?</p></pre>fortytw2: <pre><p>Rails is not a language - and has a vastly different set of goals than Go, which is a language. It's unreasonable to expect every language to be the same </p></pre>DerNalia: <pre><p>I wasn't asking if vanilla Go can do all these things....</p>
<blockquote>
<p>wondering what packages are out there could be put together to try to get as close to the rails experience (tm) as possible.</p>
</blockquote></pre>: <pre><p>[deleted]</p></pre>DerNalia: <pre><p>ha. This thread started out kind of bitter. I'm glad there are helpful people here :-)</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传